0

How can I create and get multiple IoC container instances in web application?

And in web application, there are 2 types of Spring containers - one is application context ApplicationContext and another is WebApplicationContext, I know I could have multiple WebApplicationContext if I declare multiple servlets using org.springframework.web.servlet.DispatcherServlet, so suppose I have 3 such DispatcherServlet configuration and then one is global one (using context-param), so does it mean that it would have 4 IoC containers?

And how can I get the object of those IoC container?

I have read lot of SO questions related to application context but it is driving me crazy, things are clear for application context created using ClassPathXmlApplicationContext but in case of web i.e. ApplicationContext and WebApplicationContext, things are not at clear.

Please note that I have read this link but it is for ClassPathXmlApplicationContext, but my all confusion is for application context w.r.t. to web applications.

P.S.: There is really not any purpose for why I want to do this, I am in learning phase so I am trying to understand containers.

Community
  • 1
  • 1
pjj
  • 2,015
  • 1
  • 17
  • 42
  • 1
    What is your purpose for wanting multiple containers? This sounds like an XY problem. – chrylis -cautiouslyoptimistic- May 18 '17 at 22:22
  • @chrylis There is really not any purpose, I want am in learning phase so I am trying to understand containers. – pjj May 18 '17 at 22:24
  • Then the answer is "yes, but it's extremely complicated, and it's not worth doing because I've never even heard of a situation where it's relevant"--and that was before the trend toward microservices. Note that Spring applications don't have *both* an `ApplicationContext` and a `WebApplicationContext`, `WebApplicationContext extends ApplicationContext`. – chrylis -cautiouslyoptimistic- May 18 '17 at 22:27
  • @chrylis See, this is where things are driving me crazy, check this link - http://stackoverflow.com/questions/600095/splitting-applicationcontext-to-multiple-files, as per this I can create both application context and web application context, especially check out the last answer. – pjj May 18 '17 at 22:31
  • That's some custom library that I've never seen, and I've never seen the pattern used. Especially now that Spring 5 is nearly out, and Spring Boot with JavaConfig is the de facto standard for application setup, nearly all of that is obsolete. – chrylis -cautiouslyoptimistic- May 18 '17 at 23:04

0 Answers0