org.springframework.web.context.ContextLoaderListener 1
org.springframework.web.servlet.DispatcherServlet 2
SpringWebMvc中同时配置1和2
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:ApplicationContext.xml,classpath:RedisContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:SpringMvcContext.xml</param-value>
</init-param>
</servlet>
因为1被配置在监听器标签,并实现ServletContextListener接口,所以当容器启动后,1会进行org.springframework.web.context.ContextLoaderListener#contextInitialized方法进行初始化。
初始化后,此时项目处于等待状态,等待第一个请求到来,当第一个请求到达时,2才会进行实例化并调用。
具体实例化过程,参见:https://www.cnblogs.com/hfultrastrong/p/10830517.html
ContextLoadListener & DispatcherServlet 加载顺序以及加载过程
原文:https://www.cnblogs.com/hfultrastrong/p/10832903.html