Java – association between: webapplicationcontext of springioccontainer | ApplicationContext |
background
After reading 1 2 3 4 5 6 links, I come to the following conclusions –
As spring, MVC is designed in a standard servlet and promotes the same function of servlet context and application context In spring, there are two types of context ApplicationContext and webapplicationcontext-
ApplicationContext is initialized by contextloaderlistener, and each application has a single instance Webapplicationcontext loaded by each dispatcher servlet
We can see the webapplicationcontext extended by ApplicationContext above, so what is related to ApplicationContext? Finally, this is a part of webapplicationcontext
doubt
>Which context object does applicationcontextaware provide
public class SomeThing implements ApplicationContextAware{ @Override public void setApplicationContext(ApplicationContext ctx) throws BeanException{ //this context object is `ApplicationContext` or `WebApplicationContext`? } }
>Context and container seem to be synonymous with most of us. I want to give an example Say we have two scheduler servlets, one rest and so on for MVC
First dispatcher –
public class RestInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { @Override protected String[] getServletMappings() { return new String[] { "/rest/*" }; } }
Second dispatcher –
public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { @Override protected String[] getServletMappings() { return new String[] { "/mvc/*" }; } }
There are two instances of webapplicationcontext, and those public parts are loaded by contextloaderlistner to define rootcontext
I'm not sure, but there can't be two ioccontainers in a spring application. > Beanfactory, that is, springioccontainer, is where all bean objects live. What are the objects associated with webapplicationcontext, a part of the spring container, and how does this container initialize the webapplicationcontext? I want to know how they are interrelated?
Whenever we do CTX GetBean () – this returns the object container from spring. How does this communication happen between the context and the container?
There is a similar answer, denying that both are the same, it said
So my point is why the definitions of two loaded beans are together, which is a kind of rework?
Even if web applications are spring driven, one more thing is that there must be a context provided and used by a standard servlet in HTTP communication
Spring follows this, or spring handles the problem in other ways In the spring context, this means that there is only one IOC container, part of which is loaded by the dispatcherservlet and part by the contextloaderlistner, and it can facilitate more access to static resources such as I18N
Solution
For your doubts 1
There is a separate context instance in the spring application, which is the webapplicationcntext. Net for each dispatcher servlet It can be a super interface ApplicationContext-
public class SomeThing implements ApplicationContextAware{ @Override public void setApplicationContext(ApplicationContext ctx) throws BeanException{ //this context object is `WebApplicationContext` which is refer by `ApplicationContext`. } }
In spring, context means that there is only one IOC container, some parts are loaded by contextloaderlistner, and can promote more access to static resources such as I18N
Your above understanding is almost correct In spring, all webapplicationcontext objects share some common references, namely rootcontext
This answer does not include the answers to question 2, double 3, and why all contexts perform the same task