BackGround
After reading from 1 2 3 4 5 6 Links I reached the following conclusion-
As Spring mvc designed over standered servlets,and facilitate same functionality of servlet context and application context.In spring there is two type of context ApplicationContext and WebApplicationContext-
ApplicationContext initialise by ContextLoaderListener,single instanse per application.
WebApplicationContext loaded by per DispatcherServlet.
We can understand above like this ApplicationContext extends by WebApplicationContext so what ever stuff associated with ApplicationContext at the end this is part of WebApplicationContext.
Doubts
ApplicationContextAwareoffers whichcontextobject.public class SomeThing implements ApplicationContextAware { @Override public void setApplicationContext(ApplicationContext ctx) throws BeanException { //this context object is `ApplicationContext` or `WebApplicationContext`? } }contextandcontainerseems synonyms to most of us,I want to give an example.Let say we have two dispatcher servlet one forrestand other formvc.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/*" }; } }than here there is two instance of
WebApplicationContext,those common part is loaded byContextLoaderListneras define inrootContext.I am not sure, but there must not be 2 IocContainer in a single SpringApplication.
BeanFactory ie SpringIocContainer is,where all the bean object lives,what ever objects we associates with
WebApplicationContextis part of Spring container,how does this container initialised byWebApplicationContext?I want to want to know how does they both associated with each other?And whenever we did
ctx.getBean()- this returns object from spring container,how does this communication between context and container happens?
There is a similar answer that denies the both are same,it says
Spring comes with several container implementations,Both load bean definitions, wire beans together, and dispense beans upon request,but an ApplicationContext offers much more.
So my point is why Both load bean definitions, wire beans together,this is kind of rework?
One more thing even though web-app is spring driven or not, there must be a context which standard servlet provides and used in Http communication......
Spring follows this or spring handles this in some other manner.And in spring context means a just IOC container, of which some part is loaded by DispacherServlet and some part is loaded by ContextLoaderListner and can facilitate much more such as I18N,access to static resource etc..