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>

。。。

 

Spring使用经验之Listener综述的更多相关文章

  1. Spring Boot的Listener机制的用法和实现原理详解

    之前在介绍了在spring-boot启动过程中调用runner的原理,今天我们介绍另外一种可以实现相似功能的机制:spring-boot的Listener机制. 通过注册Listener,可以实现对于 ...

  2. Spring Boot的listener简单使用

    监听器(Listener)的注册方法和 Servlet 一样,有两种方式:代码注册或者注解注册 1.代码注册方式 通过代码方式注入过滤器 @Bean     public ServletListene ...

  3. Spring使用经验之StandardServletMultipartResolver实现文件上传的基本配置

    Note:Spring使用版本是4.1.6.RELEASE 1. 在实现了AbstractAnnotationConfigDispatcherServletInitializer的类中重载custom ...

  4. Spring Boot 整合 Listener

    两种方法: 方法一: 使用注解 编写Listener,并使用@WebListener注解标记,在启动类使用注解:@ServletComponentScan package clc.user.liste ...

  5. spring boot 集成 Listener 的两种方式

    1)@ServletComponentScan注解+@WebListener注解 2)@Bean注解+ServletListenerRegistrationBean类

  6. 如何在自定义Listener(监听器)中使用Spring容器管理的bean

    正好以前项目中碰到这个问题,现在网上偶然又看到这个问题的博文,那就转一下吧. 原文:http://blog.lifw.org/post/46428852 感谢作者 另外补充下:在web Server容 ...

  7. spring boot整合servlet、filter、Listener等组件方式

    创建一个maven项目,然后此项目继承一个父项目:org.springframework.boot 1.创建一个maven项目: 2.点击next后配置父项目及版本号 3.点击finish后就可查看p ...

  8. 【Spring】23、ApplicationContext ,ApplicationContextAware,Listener,Event 的关系解读

    tomcat容器启动流程 启动tomcat容器,加载web.xml,建立整个容器(Servlet容器,这里是tomcat吧)的上下文,ServletContext,这时web.xml有个监听器,就是C ...

  9. Spring+SpringMVC+Hibernate简单整合(转)

    SpringMVC又一个漂亮的web框架,他与Struts2并驾齐驱,Struts出世早而占据了一定优势,下面同样做一个简单的应用实例,介绍SpringMVC的基本用法,接下来的博客也将梳理一下Str ...

随机推荐

  1. STL模板整理 vector

    一.什么是标准模板库(STL)? 1.C++标准模板库与C++标准库的关系 C++标准模板库其实属于C++标准库的一部分,C++标准模板库主要是定义了标准模板的定义与声明,而这些模板主要都是 类模板, ...

  2. HDU 4355.Party All the Time-三分

    Party All the Time Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  3. HDU 1426 Sudoku Killer【DFS 数独】

    自从2006年3月10日至11日的首届数独世界锦标赛以后,数独这项游戏越来越受到人们的喜爱和重视. 据说,在2008北京奥运会上,会将数独列为一个单独的项目进行比赛,冠军将有可能获得的一份巨大的奖品— ...

  4. 11.5NOIP2018提高组模拟题

    书信(letter) Description 有 n 个小朋友, 编号为 1 到 n, 他们每人写了一封信, 放到了一个信箱里, 接下来每个人从中抽取一封书信. 显然, 这样一共有 n!种拿到书信的情 ...

  5. Scrum生命周期

    Recently while cleaning up my photo albums I found some interesting old pictures which were captured ...

  6. luogu P1215 [USACO1.4]母亲的牛奶 Mother's Milk

    题目描述 农民约翰有三个容量分别是A,B,C升的桶,A,B,C分别是三个从1到20的整数, 最初,A和B桶都是空的,而C桶是装满牛奶的.有时,农民把牛奶从一个桶倒到另一个桶中,直到被灌桶装满或原桶空了 ...

  7. 【树链剖分】【线段树】bzoj3626 [LNOI2014]LCA

    引用题解: http://blog.csdn.net/popoqqq/article/details/38823457 题目大意: 给出一个n个节点的有根树(编号为0到n-1,根节点为0).一个点的深 ...

  8. 【线段树】bzoj3747 [POI2015]Kinoman

    题解:http://www.cnblogs.com/zyfzyf/p/4105184.html 一.下传标记写法 #include<cstdio> #include<algorith ...

  9. Problem V: 零起点学算法20——输出特殊值II

    #include<stdio.h> int main() { printf("\\n"); ; }

  10. iOS开发-设置在使用NavigateController时View的顶部位置

      最近我在开发中遇到了一个问题,在使用NavigationController时内部的ViewController的View总是与屏幕顶部对齐,而我们有时候不需要这种效果: 在开发过程中,我们可能会 ...