在JavaEE的程序中,我们往往要配置web.xml文件。这个文件的重要性,我就不说了。说说它与Spring框架结合时,所需要配置的几个类吧。
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的处理是相当地有能力的
分享到:
相关推荐
web.xml配置详解web.xml配置详解web.xml配置详解web.xml配置详解web.xml配置详解web.xml配置详解web.xml配置详解
spring-mvc.xml spring-mybatis.xml web.xml log4j.properties,项目中需要用到的配置文件。直接可用。
在web.xml中引入其他xml配置文件的步骤,含引入错误解决。
全面详细讲述web.xml个元素的用途 还有实例哦
web.xml配置文件详解让开发人员更加清楚web.xml是怎么配置。以及各个配置的作用。
为tomcat服务器配置https,tomcat需要设置的server.xml与web.xml配置。可以帮助小白为tomcat服务器配置https协议(域名)。
web.xml+详细解析.rarweb.xml+详细解析.rarweb.xml+详细解析.rar
加载spring 文件,在web.xml中的配置
struts.xml和applicationContext.xml、web.xml的配置
WEB-INF中的web.xml中之前增加以下配置:WEB-INF中的web.xml中之前增加以下配置:WEB-INF中的web.xml中之前增加以下配置:
spring在web.xml中和在struts中的不同配置..pdf
spring无web.xml零配置,使用javaconfig来进行spring配置,本项目使用maven管理,
web.xml 各属性作用描述 Web.xml 常用元素 <web‐app> ‐name>‐name>定义了WEB 应用的名字 <description></description> 声明WEB 应用的描述信息
本篇文章主要介绍了Spring mvc的web.xml配置说明,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
在web.xml中配置action或.do,附上详细的文档
web.xml 配置详解,需要的下载了。。。Web.xml常用元素和在java web规范中说明.按照listner,filter,servlet的顺序初始化
详细介绍web.xml 配置,便于您快速熟悉、掌握。
web.xml加载顺序与web.xml常用节点解析
Filter过滤器的代码及其web.xml配置代码 很好的解决网页乱码问题,很方便,只要按照名字添加就可以了
介绍了在web.xml配置文件中如何配置过滤器。