解析web.xml中常常需要配置几个Spring核心类
2012-09-29 23:31
218 查看
在JavaEE的程序中,我们往往要配置web.xml文件。这个文件的重要性,我就不说了。说说它与Spring框架结合时,所需要配置的几个类吧。
1. org.springframework.web.util.IntrospectorCleanupListener. 在web.xml中,我们常常的配置如下。
正如文档中所说的,“在web.xml中,这个监听器应该在任何应用程序监听器,比如Spring's ContextLoaderListener之前,作为第一个监听器被注册(上面文档最后一段)。在应用程序运行周期的正确时刻,让监听器充分发挥作用” 。
2. org.springframework.web.context.ContextLoaderListener. 这个类是程序引导监听器去开启和关闭Spring的Root,它注册在web.xml文件中的org.springframework.web.util.Log4jConfigListener配置之后。
3. org.springframework.web.context.request.RequestContextListener. 它显露Request给当前的线程(Current Thread). 这个类主要用作第三方servlet,例如the JSF FacesServlet。在Spring自己的web支持下, DispatcherServlet的处理是相当地有能力的
1. org.springframework.web.util.IntrospectorCleanupListener. 在web.xml中,我们常常的配置如下。
<listener> <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class> </listener>它的主要作用是负责处理因JavaBean Inteceptor的使用而引起的缓存泄露问题。Spring 的文档中,对这个类进行了详细的说明(Spring 3.x)。
* Listener that flushes the JDK's {@link java.beans.Introspector JavaBeans Introspector} * cache on web app shutdown. 在web.xml文件中,注册这个监听器保证恰到地释放web应用程序类加载及它所加载的
* 类(Register this listener in your <code>web.xml</code> to) guarantee proper release of
* the web application class loader and its loaded classes.
* * <p><b>If the JavaBeans Introspector has been used to analyze application classes, * the system-level Introspector cache will hold a hard reference to those classes. * Consequently, those classes and the web application class loader will not be * garbage-collected on web app shutdown!</b> This listener performs proper cleanup, * to allow for garbage collection to take effect. * * <p>Unfortunately, the only way to clean up the Introspector is to flush * the entire cache, as there is no way to specifically determine the * application's classes referenced there. This will remove cached * introspection results for all other applications in the server too. * * <p>Note that this listener is <i>not</i> necessary when using Spring's beans * infrastructure within the application, as Spring's own introspection results * cache will immediately flush an analyzed class from the JavaBeans Introspector * cache and only hold a cache within the application's own ClassLoader. * * <b>Although Spring itself does not create JDK Introspector leaks, note that this * listener should nevertheless be used in scenarios where the Spring framework classes * themselves reside in a 'common' ClassLoader (such as the system ClassLoader).</b> * In such a scenario, this listener will properly clean up Spring's introspection cache. * * <p>Application classes hardly ever need to use the JavaBeans Introspector * directly, so are normally not the cause of Introspector resource leaks. * Rather, many libraries and frameworks do not clean up the Introspector: * e.g. Struts and Quartz.(当然啦,许多库包和框架不会清理拦截器,如Struts 和 Quartz) * 既然这样,这样一个简单的缓存泄露会引起整个web引用程序的类加载不能被垃圾回收器回收。
* <p>Note that a single such Introspector leak will cause the entire web * app class loader to not get garbage collected! This has the consequence that * you will see all the application's static class resources (like singletons) * around after web app shutdown, which is not the fault of those classes! * * <p><b>This listener should be registered as the first one in <code>web.xml</code>, * before any application listeners such as Spring's ContextLoaderListener.</b> * This allows the listener to take full effect at the right time of the lifecycle.
正如文档中所说的,“在web.xml中,这个监听器应该在任何应用程序监听器,比如Spring's ContextLoaderListener之前,作为第一个监听器被注册(上面文档最后一段)。在应用程序运行周期的正确时刻,让监听器充分发挥作用” 。
2. org.springframework.web.context.ContextLoaderListener. 这个类是程序引导监听器去开启和关闭Spring的Root,它注册在web.xml文件中的org.springframework.web.util.Log4jConfigListener配置之后。
3. org.springframework.web.context.request.RequestContextListener. 它显露Request给当前的线程(Current Thread). 这个类主要用作第三方servlet,例如the JSF FacesServlet。在Spring自己的web支持下, DispatcherServlet的处理是相当地有能力的
相关文章推荐
- Spring需要的几个关键配置文件(SSM框架整合)
- 系统核心模块所需要的几个部分
- OFBiz 开发需要用到的几个重要(配置)文件
- 配置基于名称的虚拟主机需要注意的几个方面
- spring事务配置核心文件
- 基于注解Spring MVC综合Hibernate(需要jar包,spring和Hibernate整合配置,springMVC组态,重定向,)批量删除
- Spring事务配置的五种方式 -- 越往后需要Spring版本越高
- 【SpringBoot】核心依赖和自动配置
- 华三12500设备配置需要注意的几个地方
- SpringBoot核心原理:自动化配置1
- spring事务 只需要datasource 就可以的注解式配置
- spring2.5之后为了简化命名空间.xml文件的配置,引入p命名空间,需要先导入命名空间
- jboss单机和集群配置需要注意的几个关键点,亲测总结!
- spring 的核心框架包和XML文件配置
- Spring中c3p0连接池的配置 及JdbcTemplate的使用 通过XML配置文件注入各种需要对象的操作 来完成数据库添加Add()方法
- 关于nginx的几个核心配置说明
- Spring Boot核心原理-自动配置 以及@ConfigurationProperties 注解
- 基于maven开发spring项目需要配置的一些最基础的依赖
- Spring Boot核心配置
- Spring Boot核心原理-自动配置