解析web.xml中常常需要配置几个Spring核心类

  在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的处理是相当地有能力的



 

            

你可能感兴趣的:(spring,ClassLoader,cache,struts,application,javabeans)