List of usage examples for org.springframework.context.support GenericApplicationContext setParent
@Override public void setParent(@Nullable ApplicationContext parent)
From source file:com.mitre.cockpits.cmscockpit.CmsCockpitConfigurationTest.java
@BeforeClass public static void testsSetup() { Registry.setCurrentTenantByID("junit"); final GenericApplicationContext context = new GenericApplicationContext(); context.setResourceLoader(new DefaultResourceLoader(Registry.class.getClassLoader())); context.setClassLoader(Registry.class.getClassLoader()); context.getBeanFactory().setBeanClassLoader(Registry.class.getClassLoader()); context.setParent(Registry.getGlobalApplicationContext()); final XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(context); xmlReader.setBeanClassLoader(Registry.class.getClassLoader()); xmlReader.setDocumentReaderClass(ScopeTenantIgnoreDocReader.class); xmlReader.loadBeanDefinitions(getSpringConfigurationLocations()); context.refresh();//from www .jav a 2 s. c o m applicationContext = context; }
From source file:net.sourceforge.vulcan.spring.AppCtxTest.java
public void testParentReceivesFromChild() throws Exception { GenericApplicationContext child = new GenericApplicationContext(); child.setParent(this.ac); child.refresh();/* w w w. j ava 2 s.c o m*/ assertNotSame(evt, received); child.publishEvent(evt); assertSame(evt, received); }
From source file:org.cloudfoundry.identity.uaa.test.ParentContextLoader.java
@Override protected void customizeContext(GenericApplicationContext context) { GenericXmlApplicationContext parent = new GenericXmlApplicationContext(); parent.setEnvironment(TestProfileEnvironment.getEnvironment()); parent.load(parentLocation);/* w w w .ja va 2s. com*/ parent.refresh(); super.customizeContext(context); context.setParent(parent); }
From source file:org.jacpfx.vertx.spring.SpringVerticleFactory.java
private Verticle createSpringVerticle(final Class<?> currentVerticleClass, ClassLoader classLoader) { final SpringVerticle annotation = currentVerticleClass.getAnnotation(SpringVerticle.class); final Class<?> springConfigClass = annotation.springConfig(); // Create the parent context final GenericApplicationContext genericApplicationContext = new GenericApplicationContext(); genericApplicationContext.setClassLoader(classLoader); if (parentContext != null) { genericApplicationContext.setParent(parentContext); }/*from w ww. j a v a 2s . c o m*/ genericApplicationContext.refresh(); genericApplicationContext.start(); // 1. Create a new context for each verticle and use the specified spring configuration class if possible AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(); annotationConfigApplicationContext.setParent(genericApplicationContext); annotationConfigApplicationContext.register(SpringContextConfiguration.class, springConfigClass); // 2. Register a bean definition for this verticle annotationConfigApplicationContext.registerBeanDefinition(currentVerticleClass.getSimpleName(), new VerticleBeanDefinition(currentVerticleClass)); // 3. Add a bean factory post processor to avoid configuration issues annotationConfigApplicationContext .addBeanFactoryPostProcessor(new SpringSingleVerticleConfiguration(currentVerticleClass)); annotationConfigApplicationContext.refresh(); annotationConfigApplicationContext.start(); annotationConfigApplicationContext.registerShutdownHook(); // 5. Return the verticle by fetching the bean from the context return (Verticle) annotationConfigApplicationContext.getBeanFactory() .getBean(currentVerticleClass.getSimpleName()); }
From source file:de.hybris.platform.btgcockpit.service.BTGCockpitServiceTest.java
public void initApplicationContext() { final GenericApplicationContext context = new GenericApplicationContext(); context.setResourceLoader(new DefaultResourceLoader(Registry.class.getClassLoader())); context.setClassLoader(Registry.class.getClassLoader()); context.getBeanFactory().setBeanClassLoader(Registry.class.getClassLoader()); context.setParent(Registry.getGlobalApplicationContext()); final XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(context); xmlReader.setDocumentReaderClass(ScopeTenantIgnoreDocReader.class); xmlReader.setBeanClassLoader(Registry.class.getClassLoader()); xmlReader.loadBeanDefinitions(getSpringConfigurationLocations()); context.refresh();/* w ww . j a v a 2 s.co m*/ final AutowireCapableBeanFactory beanFactory = context.getAutowireCapableBeanFactory(); beanFactory.autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, true); this.applicationContex = context; }
From source file:org.springframework.boot.context.logging.LoggingApplicationListenerTests.java
@Test public void closingChildContextDoesNotCleanUpLoggingSystem() { System.setProperty(LoggingSystem.SYSTEM_PROPERTY, TestCleanupLoggingSystem.class.getName()); multicastEvent(new ApplicationStartingEvent(this.springApplication, new String[0])); TestCleanupLoggingSystem loggingSystem = (TestCleanupLoggingSystem) ReflectionTestUtils .getField(this.initializer, "loggingSystem"); assertThat(loggingSystem.cleanedUp).isFalse(); GenericApplicationContext childContext = new GenericApplicationContext(); childContext.setParent(this.context); multicastEvent(new ContextClosedEvent(childContext)); assertThat(loggingSystem.cleanedUp).isFalse(); multicastEvent(new ContextClosedEvent(this.context)); assertThat(loggingSystem.cleanedUp).isTrue(); childContext.close();//w ww . j a v a2s. com }
From source file:org.springframework.test.context.support.AbstractGenericContextLoader.java
/** * Load a Spring ApplicationContext from the supplied {@link MergedContextConfiguration}. * * <p>Implementation details://w w w. j av a 2s.c om * * <ul> * <li>Calls {@link #validateMergedContextConfiguration(MergedContextConfiguration)} * to allow subclasses to validate the supplied configuration before proceeding.</li> * <li>Creates a {@link GenericApplicationContext} instance.</li> * <li>If the supplied {@code MergedContextConfiguration} references a * {@linkplain MergedContextConfiguration#getParent() parent configuration}, * the corresponding {@link MergedContextConfiguration#getParentApplicationContext() * ApplicationContext} will be retrieved and * {@linkplain GenericApplicationContext#setParent(ApplicationContext) set as the parent} * for the context created by this method.</li> * <li>Calls {@link #prepareContext(GenericApplicationContext)} for backwards * compatibility with the {@link org.springframework.test.context.ContextLoader * ContextLoader} SPI.</li> * <li>Calls {@link #prepareContext(ConfigurableApplicationContext, MergedContextConfiguration)} * to allow for customizing the context before bean definitions are loaded.</li> * <li>Calls {@link #customizeBeanFactory(DefaultListableBeanFactory)} to allow for customizing the * context's {@code DefaultListableBeanFactory}.</li> * <li>Delegates to {@link #loadBeanDefinitions(GenericApplicationContext, MergedContextConfiguration)} * to populate the context from the locations or classes in the supplied * {@code MergedContextConfiguration}.</li> * <li>Delegates to {@link AnnotationConfigUtils} for * {@link AnnotationConfigUtils#registerAnnotationConfigProcessors registering} * annotation configuration processors.</li> * <li>Calls {@link #customizeContext(GenericApplicationContext)} to allow for customizing the context * before it is refreshed.</li> * <li>Calls {@link #customizeContext(ConfigurableApplicationContext, MergedContextConfiguration)} to * allow for customizing the context before it is refreshed.</li> * <li>{@link ConfigurableApplicationContext#refresh Refreshes} the * context and registers a JVM shutdown hook for it.</li> * </ul> * * @return a new application context * @see org.springframework.test.context.SmartContextLoader#loadContext(MergedContextConfiguration) * @see GenericApplicationContext * @since 3.1 */ @Override public final ConfigurableApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception { if (logger.isDebugEnabled()) { logger.debug(String.format("Loading ApplicationContext for merged context configuration [%s].", mergedConfig)); } validateMergedContextConfiguration(mergedConfig); GenericApplicationContext context = new GenericApplicationContext(); ApplicationContext parent = mergedConfig.getParentApplicationContext(); if (parent != null) { context.setParent(parent); } prepareContext(context); prepareContext(context, mergedConfig); customizeBeanFactory(context.getDefaultListableBeanFactory()); loadBeanDefinitions(context, mergedConfig); AnnotationConfigUtils.registerAnnotationConfigProcessors(context); customizeContext(context); customizeContext(context, mergedConfig); context.refresh(); context.registerShutdownHook(); return context; }