/** * Refresh the underlying {@link ApplicationContext}. * @param applicationContext the application context to refresh */ protected void refresh(ApplicationContext applicationContext) { Assert.isInstanceOf(AbstractApplicationContext.class, applicationContext); ((AbstractApplicationContext) applicationContext).refresh(); }
AbstractApplicationContext appContext = new ClassPathXmlApplicationContext( new String[] {"applicationContext.xml"}, false ); appContext.getEnvironment().getPropertySources().addLast( new CustomPropertySource() ); appContext.refresh();
public AbstractApplicationContext initSpring(ServletContextEvent sce) { context = new CseXmlWebApplicationContext(sce.getServletContext()); context.refresh(); return context; }
@Test public void testAsyncMulticaster() throws Exception { AbstractApplicationContext context = new ClassPathXmlApplicationContext( "messageBusWithAsyncEventMulticaster.xml", this.getClass()); context.refresh(); SimpleApplicationEventMulticaster multicaster = (SimpleApplicationEventMulticaster) context.getBean(AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME); DirectFieldAccessor accessor = new DirectFieldAccessor(multicaster); Object taskExecutor = accessor.getPropertyValue("taskExecutor"); assertEquals(ThreadPoolTaskExecutor.class, taskExecutor.getClass()); context.close(); }
@Test public void testAsyncMulticasterExplicitlySetToFalse() throws Exception { AbstractApplicationContext context = new ClassPathXmlApplicationContext( "messageBusWithoutAsyncEventMulticaster.xml", this.getClass()); context.refresh(); SimpleApplicationEventMulticaster multicaster = (SimpleApplicationEventMulticaster) context.getBean(AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME); DirectFieldAccessor accessor = new DirectFieldAccessor(multicaster); Object taskExecutor = accessor.getPropertyValue("taskExecutor"); if (SpringVersion.getVersion().startsWith("2")) { assertEquals(SyncTaskExecutor.class, taskExecutor.getClass()); } else { assertNull(taskExecutor); } context.close(); }
@Test //INT-2649 public void testRollbackOnDelayerHandlerReleaseTask() throws Exception { AbstractApplicationContext context = new ClassPathXmlApplicationContext("DelayerHandlerRescheduleIntegrationTests-context.xml", getClass()); MessageChannel input = context.getBean("transactionalDelayerInput", MessageChannel.class); MessageGroupStore messageStore = context.getBean("messageStore", MessageGroupStore.class); String delayerMessageGroupId = UUIDConverter.getUUID("transactionalDelayer.messageGroupId").toString(); assertEquals(0, messageStore.messageGroupSize(delayerMessageGroupId)); input.send(MessageBuilder.withPayload("test").build()); Thread.sleep(1000); assertEquals(1, messageStore.messageGroupSize(delayerMessageGroupId)); //To check that 'rescheduling' works in the transaction boundaries too context.close(); context.refresh(); assertTrue(RollbackTxSync.latch.await(20, TimeUnit.SECONDS)); //On transaction rollback the delayed Message should remain in the persistent MessageStore assertEquals(1, messageStore.messageGroupSize(delayerMessageGroupId)); context.close(); }
@Test public void testProcessMessageWithParameterCoercionToNonPrimitive() throws Exception { class TestTarget { @SuppressWarnings("unused") public String find(Resource[] resources) { return Arrays.toString(resources); } } Expression expression = expressionParser.parseExpression("#target.find(payload)"); ExpressionEvaluatingMessageProcessor<String> processor = new ExpressionEvaluatingMessageProcessor<>(expression); AbstractApplicationContext applicationContext = new GenericApplicationContext(); processor.setBeanFactory(applicationContext); IntegrationEvaluationContextFactoryBean factoryBean = new IntegrationEvaluationContextFactoryBean(); factoryBean.setApplicationContext(applicationContext); applicationContext.getBeanFactory() .registerSingleton(IntegrationContextUtils.INTEGRATION_EVALUATION_CONTEXT_BEAN_NAME, factoryBean.getObject()); applicationContext.refresh(); processor.afterPropertiesSet(); EvaluationContext evaluationContext = TestUtils.getPropertyValue(processor, "evaluationContext", EvaluationContext.class); evaluationContext.setVariable("target", new TestTarget()); String result = processor.processMessage(new GenericMessage<>("classpath*:*-test.xml")); assertTrue("Wrong result: " + result, result.contains("log4j2-test.xml")); }
IntegrationRegistrar registrar = new IntegrationRegistrar(); registrar.registerBeanDefinitions(null, (BeanDefinitionRegistry) context.getBeanFactory()); context.refresh(); handler.setBeanFactory(context); handler.setUriVariablesExpression(new SpelExpressionParser().parseExpression("headers.uriVariables"));
assertEquals(message1, ((DelayHandler.DelayedMessageWrapper) payload).getOriginal()); context.refresh();
assertEquals(message1, ((DelayHandler.DelayedMessageWrapper) payload).getOriginal()); context.refresh();
assertEquals(message1, ((DelayHandler.DelayedMessageWrapper) payload).getOriginal()); context.refresh();
public AbstractApplicationContext getApplicationContext() { if (applicationContext != null) { return applicationContext; } else { final String config = getConfig(); if (config == null) { applicationContext = new ClassPathXmlApplicationContext(DEFAULT_CONFIG_LOCATION); } else { applicationContext = new FileSystemXmlApplicationContext("file:" + config); } applicationContext.setClassLoader(getClass().getClassLoader()); applicationContext.refresh(); } return applicationContext; }
public void setConfig(String config) { this.config = config; logger.debug("Loading configuration from [" + config + "]."); try { applicationContext = new FileSystemXmlApplicationContext( new String[] { "file:" + config }, false); applicationContext.setClassLoader(getClass().getClassLoader()); applicationContext.refresh(); this.applicationContext.getBeanFactory().autowireBeanProperties( this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, isDependencyCheck()); } catch (Exception ex) { ex.printStackTrace(); throw new RuntimeException(ex); } } }
public void onApplicationEvent(ApplicationEvent event) { // only respond to ContextRefreshedEvents that are sourced from the parent context if (event.getSource() != parent) return; if (event instanceof ContextRefreshedEvent) { if (logger.isDebugEnabled()) logger.debug(format("Caught ContextRefreshedEvent from parent application context [%s], now refreshing [%s]", parent.getDisplayName(), child.getDisplayName())); copyBeanFactoryPostProcessors(); child.setParent(parent); child.refresh(); return; } if (event instanceof ContextClosedEvent) { if (logger.isDebugEnabled()) logger.debug(format("Caught ContextClosedEvent from parent application context [%s], now closing [%s]", parent.getDisplayName(), child.getDisplayName())); child.close(); return; } }
static public AbstractApplicationContext load() { AbstractApplicationContext context; try { context = AnnotationConfigApplicationContext.class.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } AnnotationConfigRegistry registry = (AnnotationConfigRegistry) context; registry.register(BaseConfiguration.class); registry.register(GraphQLJavaToolsAutoConfiguration.class); context.refresh(); return context; }
@Before public void setUp() { context.refresh(); nodeList = new ArrayList<>(); setPeerHandlerFactory(); }
@Override protected Scope doStart(Scope aExternalScope) { SpringComponent old = THIS.get(); Scope oldScope = SCOPE.get(); THIS.set(this); Scope scope = new DefaultScope(getProvidedInterfaces().toArray( new ProvidedInterface[0]), aExternalScope); SCOPE.set(scope); try { GenericApplicationContext parentContext = new GenericApplicationContext(); registerRequiredServices(parentContext); registerPropertyObjects(parentContext); parentContext.refresh(); System.out.println("Parent context " + parentContext); AbstractApplicationContext context = parseConfigFiles(parentContext); context.addBeanFactoryPostProcessor(new PropertySetter(properties)); context.refresh(); exposeProvidedServices(context, aExternalScope); scope.put(CONTEXT_KEY, context); return scope; } catch (Exception e) { throw new SystemAssemblyException( "Failed to assemble spring system " + getName(), e); } finally { THIS.set(old); SCOPE.set(oldScope); } }
private void createChildContext() { if (appMetadata.isWebapp()) { applicationContext = new AnnotationConfigWebApplicationContext(); if (appMetadata.getConfigurationClasses().length > 0) { ((AnnotationConfigWebApplicationContext) applicationContext).register(appMetadata.getConfigurationClasses()); } } else { applicationContext = new AnnotationConfigApplicationContext(); if (appMetadata.getConfigurationClasses().length > 0) { ((AnnotationConfigApplicationContext) applicationContext).register(appMetadata.getConfigurationClasses()); } } applicationContext.setParent(bootstrapApplicationContext); applicationContext.getEnvironment().getPropertySources().addFirst(new ArchaiusSpringPropertySource(appMetadata.getName() + "-archaius")); PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer(); configurer.setEnvironment(applicationContext.getEnvironment()); applicationContext.addBeanFactoryPostProcessor(configurer); applicationContext.setId(appMetadata.getName()); applicationContext.refresh(); }
((AbstractApplicationContext)ctx).refresh();