首页 > 其他 > 详细

ContextLoadListener & DispatcherServlet 加载顺序以及加载过程

时间:2019-05-08 17:11:26      阅读:134      评论:0      收藏:0      [点我收藏+]

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!