zoukankan      html  css  js  c++  java
  • Spring使用经验之Listener综述

    Note:Spring使用版本是4.1.6.RELEASE

    1. ContextLoaderListener最基本的SpringListener,加载Spring配置文件

    配置名为contextConfigLocation的上下文参数,配合ContextLoaderListener使用

    <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:spring*.xml</param-value>
    </context-param>

    <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    2. WebAppRootListener用于获得name为webAppRootKey的context-param的value,在代码中使用System.getProperty(value)获得web的根目录的物理路径

    必须配置名为webAppRootKey的上下文参数,其参数默认为webapp.root,值本身实际上可以为任意值,是个key而已,但一般仍为默认值

    <context-param>
      <param-name>webAppRootKey</param-name>
      <param-value>webapp.root</param-value>
    </context-param>

    <listener>
      <listener-class>org.springframework.web.util.WebAppRootListener</listener-class>
    </listener>

    3. Log4jConfigListener 用于绑定Log4j,可动态的改变记录级别和策略,在log4j的配置文件中可使用${webapp.root},需配合Log4j使用

    必须配置名为log4jConfigLocation的Log4j的上下文参数,Log4j本身可独立使用,也可和Spring绑定使用

    <context-param>
      <param-name>log4jConfigLocation</param-name>
      <param-value>classpath:log4j.properties</param-value>
    </context-param>

    <listener>
      <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>

    4. RequestContextListener当需要定义scope是request/session/globalSession的bean时,需要启动这个Listener

    <listener>
      <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>

    5. IntrospectorCleanupListener清除Introspector, 以防止由于JavaBean Introspector使用而引起的缓冲泄露

    <listener>
      <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
    </listener>

    。。。

     

  • 相关阅读:
    web2.0网站如何设计UE/UI
    SQL查询入门(中篇)
    跟我学做c#皮肤美化(三)
    王通:SEO成功的秘密
    26个Jquery使用小技巧(jQuery tips, tricks & solutions)
    跟我学做c#皮肤美化(五)
    js iframe子父页面读取方式
    我的新网站上线了历史五千年www.lswqn.com在诵读经典中传承中华文明
    jQuery获取Radio,CheckBox选择的Value值
    C#仿QQ皮肤-主窗体MainForm和Main的实现
  • 原文地址:https://www.cnblogs.com/zjm701/p/6831170.html
Copyright © 2011-2022 走看看