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. activemq修改admin密码

    vim /usr/local/activemq/conf/jetty-realm.properties 用户名:密码,角色 mq: 123, admin 那么打开管理后台,用户是mq,密码是123,具 ...

  2. 我从没理解js的闭包,直到他人向我这么解释。。。

    前段时间根据执行上下文写过一次闭包,但是写的简陋些.昨天在twitter上看到这篇文章,感觉背包的比喻挺恰当的.所以就翻译了. 这篇文章有些啰嗦,但是讲解很细,希望还是耐心看完.也欢迎指出错误. 原地 ...

  3. HDU 6330.Problem L. Visual Cube-模拟到上天-输出立方体 (2018 Multi-University Training Contest 3 1012)

    6330.Problem L. Visual Cube 这个题就是输出立方体.当时写完怎么都不过,后来输出b<c的情况,发现这里写挫了,判断失误.加了点东西就过了,mdzz... 代码: //1 ...

  4. ACM-ICPC北京赛区(2017)网络赛2【后缀数组+Java//不会】

    #1579 : Reverse Suffix Array 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 There is a strong data structure ...

  5. Android学习--广播机制

    广播机制简介 Android的广播可以分为两种类型的,标准广播和有序的广播: 标准广播:  是一种完全异步执行的广播,在广播发出去之后,所有的广播接收器几乎是同一时接收到这条广播. 有序广播:  是一 ...

  6. Codeforces Beta Round 84 (Div. 2 Only)

    layout: post title: Codeforces Beta Round 84 (Div. 2 Only) author: "luowentaoaa" catalog: ...

  7. 训练指南 UVALive - 4043(二分图匹配 + KM算法)

    layout: post title: 训练指南 UVALive - 4043(二分图匹配 + KM算法) author: "luowentaoaa" catalog: true ...

  8. python3-开发面试题(python)6.22基础篇(1)

    1.为什么学习Python? 1.语言排行榜 2.语言本身简洁,优美,功能超级强大的 3.跨平台 4.非常火爆的社区 5.用的公司的多 2.通过什么途径学习的Python? 某宝2.8就搞定了,跟着视 ...

  9. [CF607D]Power Tree

    题目大意: 一棵树初始只有一个编号为$1$的权值为$w_1$的根.$q(q\le2\times10^5)$次操作,每次可以给出$v,w(w<10^9)$,新建一个结点作为$v$的子结点,权值为$ ...

  10. springmvc与前端数据交互实例

      一.从页面接收参数 Spring MVC接收请求提交的参数值的几种方法: 使用HttpServletRequest获取. @RequestMapping("/login.do" ...