@Test public void methodExpressionHandlerInParentContextLoads() { parent = new GenericXmlApplicationContext( "org/springframework/security/config/method/sec2499/parent.xml"); child = new GenericXmlApplicationContext(); child.load("org/springframework/security/config/method/sec2499/child.xml"); child.setParent(parent); child.refresh(); } }
@Test public void testCustomIdGenerationWithParentChildIndependentCreation() throws Exception { ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext("MessageIdGenerationTests-context-withGenerator.xml", this.getClass()); GenericXmlApplicationContext child = new GenericXmlApplicationContext(); child.load("classpath:/org/springframework/integration/core/MessageIdGenerationTests-context.xml"); child.setParent(parent); child.refresh(); IdGenerator idGenerator = child.getBean("idGenerator", IdGenerator.class); MessageChannel inputChannel = child.getBean("input", MessageChannel.class); inputChannel.send(new GenericMessage<Integer>(0)); verify(idGenerator, atLeastOnce()).generateId(); child.close(); parent.close(); this.assertDestroy(); }
@Test public void testCustomIdGenerationWithParentChildIndependentCreationChildrenRegistrarsOneAtTheTime() throws Exception { ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext("MessageIdGenerationTests-context.xml", this.getClass()); GenericXmlApplicationContext childA = new GenericXmlApplicationContext(); childA.load("classpath:/org/springframework/integration/core/MessageIdGenerationTests-context-withGenerator.xml"); childA.setParent(parent); childA.refresh(); childA.close(); GenericXmlApplicationContext childB = new GenericXmlApplicationContext(); childB.load("classpath:/org/springframework/integration/core/MessageIdGenerationTests-context-withGenerator.xml"); childB.setParent(parent); childB.refresh(); parent.close(); childB.close(); this.assertDestroy(); }
public AbstractApplicationContext createSubContext(final AbstractApplicationContext parent, final String path, final boolean allowBeanOverride) { final GenericXmlApplicationContext subContext = new GenericXmlApplicationContext(); subContext.setParent(parent); subContext.setAllowBeanDefinitionOverriding(allowBeanOverride); subContext.load(path); subContext.refresh(); return subContext; }
private SpringContextServiceReference load( final String serviceId, final Map<String, String> updatedProperties) { final String configurationPath = serviceDefinition.getMainContextPath(); final String serviceBeanName = serviceDefinition.getServiceBeanName(); final PropertyPlaceholderConfigurer placeholderConfigurer = createPlaceholderConfigurer(); Properties properties = new Properties(); properties.putAll(updatedProperties); properties.put(ServiceConstants.SERVICE_ID_PROPERTY, serviceId); placeholderConfigurer.setProperties(properties); final GenericXmlApplicationContext context = new GenericXmlApplicationContext(); for(Entry<String, BeanPostProcessor> postProcessorEntry: applicationContext.getBeansOfType(BeanPostProcessor.class).entrySet()){ context.getBeanFactory().registerSingleton(postProcessorEntry.getKey(), postProcessorEntry.getValue()); } context.load(configurationPath); context.setParent(applicationContext); context.addBeanFactoryPostProcessor(placeholderConfigurer); context.registerShutdownHook(); context.refresh(); final SpringContextServiceReference serviceReference; if (StringUtils.isNotBlank(serviceBeanName)) { serviceReference = findBeanByName(serviceBeanName, context); } else { serviceReference = findBeanByClass(context); } return serviceReference; }
applicationContext.setParent(parent); applicationContext.setClassLoader(classLoader);
applicationContext.setParent(parent); applicationContext.setClassLoader(classLoader);
applicationContext.setParent(parent); applicationContext.setClassLoader(classLoader);