我想知道如何在Spring的单个项目中创建多个IOC容器?
答案 0 :(得分:1)
这是
ClassPathXmlApplicationContext ctx1 = new ClassPathXmlApplicationContext("context1.xml");
ClassPathXmlApplicationContext ctx2 = new ClassPathXmlApplicationContext("context2.xml");
答案 1 :(得分:1)
您只需创建两个独立的IOC容器即可创建它们。
ApplicationContext contextA = new GenericXmlApplicationContext("classpath:contextA.xml");
ApplicationContext contextB = new GenericXmlApplicationContext("classpath:contextB.xml");
您还可以通过AbstractApplicationContext.setParent(ApplicationContext)
ApplicationContext parent =...
AbstractApplicationContext contextA = new GenericXmlApplicationContext("classpath:contextA.xml");
contextA.setParent(parent);
AbstractApplicationContext contextB = new GenericXmlApplicationContext("classpath:contextB.xml");
contextB.setParent(parent);