你的位置:首页 > 软件开发 > Java > HttpPutFormContentFilter 和 ContextLoaderListener 讲解

HttpPutFormContentFilter 和 ContextLoaderListener 讲解

发布时间:2017-07-23 00:00:20
1 ContextLoaderListener 继承自ContextLoader,并且实现ServletContextListener接口。肯定得实现这个接口了,不然怎么作为Servlet的**呢。。。ContextLoaderListener 源代码很简单,核心是实现 ...

1 ContextLoaderListener 继承自ContextLoader,并且实现ServletContextListener接口

肯定得实现这个接口了,不然怎么作为Servlet的**呢。。。

ContextLoaderListener 源代码很简单,核心是实现了 ServletContextListener 的contextInitialized和contextDestroyed方法。

因为 contextInitialized和contextDestroyed 方法分别调用了 ContextLoader里面的initWebApplicationContext和closeWebApplicationContext方法

所以核心最终还是 ContextLoader 实现了这个**,那这个**实现了什么功能呢,我们发现有两个重要属性

contextConfigLocation:即在web.

currentContextPerThread:保存了当前WebApplicationContext

其实**的加载过程可以描述为:

先判WebApplicationContext是否已存在,不存在的话则初始化一个

将我们配置的各种bean都添加到

并且可以发现 ContextLoader还提供了获取当前 WebApplicationContext的静态方法:之所以能获取,是因为initWebApplicationContext初始化方法把创建的

因为 ContextLoaderListener 本质上是创建了一个 WebApplicationContext ,所以你的项目里面,如果不使用 WebApplicationContext 就可以不配置 ContextLoaderListener 节点。

如果不配  ,

<!-- Spring MVC -->   <servlet>     <servlet-name>teach</servlet-name>     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>     <init-param>       <param-name>contextConfigLocation</param-name>       <param-value>/WEB-INF/spring-servlet.1</load-on-startup>   </servlet>   <servlet-mapping>     <servlet-name>teach</servlet-name>     <url-pattern>*.action</url-pattern>   </servlet-mapping> 

原标题:HttpPutFormContentFilter 和 ContextLoaderListener 讲解

关键词:Listener

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。