3

I want to know how can we create more than one IOC Container in a single project of the Spring ?

2 Answers 2

1

Here it is

 ClassPathXmlApplicationContext ctx1 = new ClassPathXmlApplicationContext("context1.xml"); ClassPathXmlApplicationContext ctx2 = new ClassPathXmlApplicationContext("context2.xml"); 
Sign up to request clarification or add additional context in comments.

Comments

1

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); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.