Outline
Container : is used for storing things, spring container is used to store spring of the bean, it can be simply understood as an array.
Context : so and so up and down, there may be a use in multiple contexts such as yourself can be referred to Zhang context, your hand John's hand context, is to represent a particular object, which put it about this particular. object information, all you want to get something, you can get from the context object.
General web applications require a /webapp/WEB-INF/web.xml files, also called the deployment descriptor, under normal circumstances, without this tomcat would think this is not a web application, deploy the servlet container can not go.
Web. xml can be understood to represent a web application, he was loaded by the web container (tomcat) use, which can be defined three major components :
- Listener (listener): Listen ServletContext object's life cycle in which to do something.
- Filter (filter): Filter used to intercept the request.
- Servlet: Used for forwarding the request and response
Web container loading sequence elements of web.xml
Mr. web.xml when loading into a ServletContext, then the context-param parameter values configured into the ServletContext, then at operation Listener, Filter, Servlet, etc. These objects can be acquired by ServletContext.
Therefore, the sequence should Yes:servletcontext->context-param -> listener -> filter -> servlet
ServletContext application context
ServletContextOn behalf of the entire application, an application is only one context, in any code can get into the context of the stuff inside, which kept a lot of time to initialize the object.
Spring Framework and SpringMVC
These are two frameworks also cooked two container vessels, said his son, general Spring Bean used to manage the dependencies (IOC) is still one of AOP, Spring's core function point, is mainly used to manage the bean Service layer.
when the container starts will load the configuration in web.xml spring profile address.
after allowing the generated WebApplicationContext into the ServletContext, which after use can be used.
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class> org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
Controller SpringMVC layer is a frame, is mainly used for controlling the forwarding of the request,
after completion of the initialization SpringMVC container, provided the container will Spring SpringMVC parent container, so SpringMVC Spring inside the container may be something less than but Spring SpringMVC inside.