Spring mvc 集成了Spring ioc。在Spring mvc中有一个自己的ServletContext的WebApplicationContext容器其父容器是Spring中有ApplicationContext容器。也就是说
ServletContext的WebApplicationContext容器有自己的上下文,并且能获取全局上下文的对象。WebApplicationContext的容器的都管理了Spring mvc 的Controllers等对象。
Spring mvc启动其实就是SPring MVC容器的创建。Spring mvc容器创建的过程依赖于Servlet容器的生命周期。在Servlet容器的生命周期中的ServletContextListener中来触发。这个可以从Web.xml的配置看出来
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/application.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
WebApplicationContext在ContextLoaderListerner的创建时序图如下.