I want to know how can we create more than one IOC Container in a single project of the Spring ?
2 Answers
You can create two independent IOC Containers just by creating them.
ApplicationContext contextA = new GenericXmlApplicationContext("classpath:contextA.xml"); ApplicationContext contextB = new GenericXmlApplicationContext("classpath:contextB.xml"); You can also create two or more IOC Contains that depends in a parent/child relationship (like Spring Core Context and Spring Web Context does (ContextLoaderListener or not?)) via 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);