ClassPathXmlApplicationContext parentContext = new ClassPathXmlApplicationContext(
"childcontainer/parent-with-child-context.xml"){
@Override
protected DefaultListableBeanFactory createBeanFactory() {
DefaultListableBeanFactory beanFactory = super.createBeanFactory();
beanFactory.addBeanPostProcessor(new ServiceRegistryPostProcessor(serviceRegistry, null));
return beanFactory;
}
};
parentContext.getBean("parent");
Parent parentBean = (Parent) parentContext.getBean("parent");
Child child = parentBean.tryGetChild();
try {
child.childMethod();
fail();
}
catch (NoServiceException e) {
}
// now create child appliction context
ClassPathXmlApplicationContext childContext = new ClassPathXmlApplicationContext(
new String[] { "childcontainer/child-context.xml" }, parentContext){
@Override
protected DefaultListableBeanFactory createBeanFactory() {
DefaultListableBeanFactory beanFactory = super.createBeanFactory();
beanFactory.addBeanPostProcessor(new ServiceRegistryPostProcessor(serviceRegistry, null));
beanFactory.addBeanPostProcessor(new ModuleDefinitionPostProcessor(new SimpleModuleDefinition("module1")));
return beanFactory;
}
};