RequestContextListener有什么用
The ApplicationContext
is where your Spring beans live. The purpose of the ContextLoaderListener
is two-fold:
to tie the lifecycle of the
ApplicationContext
to the lifecycle of theServletContext
andto automate the creation of the
ApplicationContext
, so you don't have to write explicit code to do create it - it's a convenience function.
Another convenient thing about the ContextLoaderListener
is that it creates a WebApplicationContext
and WebApplicationContext
provides
access to the ServletContext
via ServletContextAware
beans and the getServletContext
method.
ServletContext定义了一些方法方便Servlet和Servlet容器进行通讯,在一个web应用中所有的Servlet都共用一个ServletContext,Spring在和web应用结合使用的时候,
是将Spring的容器存到ServletContext中的;而ServletContextListener用于监听ServletContext一些事件。
WebApplicationContext
. Simply delegates to ContextLoader
as well as to ContextCleanupListener
.public class ContextLoaderListener extends ContextLoader implements ServletContextListener {
/**
* Initialize the root web application context.
*/
@Override
public void contextInitialized(ServletContextEvent event) {
initWebApplicationContext(event.getServletContext());
} /**
* Close the root web application context.
*/
@Override
public void contextDestroyed(ServletContextEvent event) {
closeWebApplicationContext(event.getServletContext());
ContextCleanupListener.cleanupAttributes(event.getServletContext());
}
在initWebApplicationContext里面有详细信息
if (this.context == null) {
this.context = createWebApplicationContext(servletContext);
}
if (this.context instanceof ConfigurableWebApplicationContext) {
ConfigurableWebApplicationContext cwac = (ConfigurableWebApplicationContext) this.context;
if (!cwac.isActive()) {
// The context has not yet been refreshed -> provide services such as
// setting the parent context, setting the application context id, etc
if (cwac.getParent() == null) {
// The context instance was injected without an explicit parent ->
// determine parent for root web application context, if any.
ApplicationContext parent = loadParentContext(servletContext);
cwac.setParent(parent);
}
configureAndRefreshWebApplicationContext(cwac, servletContext);
}
}
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.context);
由最后一句可知,WeApplicationContext的实例,存放在servletContext中。

文件内容:
# Default WebApplicationContext implementation class for ContextLoader.
# Used as fallback when no explicit context implementation has been specified as context-param.
# Not meant to be customized by application developers. org.springframework.web.context.WebApplicationContext=org.springframework.web.context.support.XmlWebApplicationContext
RequestContextListener有什么用的更多相关文章
- RequestContextListener作用
spring IOC容器实例化Bean的方式有: singleton 在spring IOC容器中仅存在一个Bean实例,Bean以单实例的方式存在. prototype ...
- spring IOC容器实例化Bean的方式与RequestContextListener应用
spring IOC容器实例化Bean的方式有: singleton 在spring IOC容器中仅存在一个Bean实例,Bean以单实例的方式存在. prototype 每次从容器中调用Bean时, ...
- request.RequestContextListener
由于是使用spring mvc来做项目,因此脱离了HttpServletRequest作为参数,不能够直接使用request,要想使用request可以使用下面的方法: 在web点xml中配置一个监听 ...
- Spring的作用域以及RequestContextListener作用<转>
一.配置方式 在Spring2.0中除了以前的Singleton和Prototype外又加入了三个新的web作用域,分别为request.session和global session,如果你想让你的容 ...
- ContextLoaderListener与RequestContextListener配置问题
转自:https://blog.csdn.net/yyqhwr/article/details/83381447 SSH2.SSM等web应用开发框架的配置过程中,因为都要用到spring,所以,往往 ...
- SSM框架中,ContextLoaderListener与RequestContextListener的联系与区别
在整合SSM框架时,我们要在web.xml文件中对spring进行相关配置. 首先要配置一个<context-param></context-param> <!--加载s ...
- 在springmvc中使用requestContextListener获取全部的request对象
RequestContextListener实现了 ServletRequestListener ,在其覆盖的requestInitialized(ServletRequestEvent reques ...
- spring笔记6 spring IOC的中级知识
1,spring ioc的整体流程,xml配置 spring ioc初始化的流程结合上图 步骤编号 完成的工作 1 spring容器读取配置文件,解析称注册表 2 根据注册表,找到相应的bean实现类 ...
- Java web.xml 配置详解
在项目中总会遇到一些关于加载的优先级问题,近期也同样遇到过类似的,所以自己查找资料总结了下,下面有些是转载其他人的,毕竟人家写的不错,自己也就不重复造轮子了,只是略加点了自己的修饰. 首先可以肯定的是 ...
随机推荐
- BZOJ3748 : [POI2015]Kwadraty
打表可得结论: 1.只有2,3,6,7,8,11,12,15,18,19,...,108,112,128这31个数的k值是无穷大 2.当n足够大的时候,即当n>506时,设$f(x)=1^2+2 ...
- BZOJ4123 : [Baltic2015]Hacker
黑掉的一定是一个长度为$\lfloor\frac{n+1}{2}\rfloor$的区间. 于是枚举初始点,然后查询包含它的区间的最小值. 通过维护前后缀最小值+单调队列$O(n)$解决. #inclu ...
- 一人一python挑战题解
题目id: 1 just print a+b give you two var a and b, print the value of a+b, just do it!! print a+b 题目id ...
- Java之美[从菜鸟到高手演变]之HashMap、HashTable(转载)
http://blog.csdn.net/zhangerqing/article/details/8193118
- 字符串全排列(permutation)
Reference: http://www.cnblogs.com/sujz/archive/2011/06/16/2082831.html 问题:给定字符串S,生成该字符串的全排列. 方法1:依次从 ...
- 【wikioi】1250 Fibonacci数列(矩阵乘法)
http://wikioi.com/problem/1250/ 我就不说这题有多水了. 0 1 1 1 矩阵快速幂 #include <cstdio> #include <cstri ...
- Graph database_neo4j 底层存储结构分析(5)
3.5 Property 的存储 下面是neo4j graph db 中,Property数据存储对应的文件: neostore.propertystore.db neostore.propertys ...
- Hadoop分布式文件系统:架构和设计要点
原文:http://hadoop.apache.org/core/docs/current/hdfs_design.html 一.前提和设计目标 1.硬件错误是常态,而非异常情况, HDFS可能是有成 ...
- OpenCV 2.4.10 Linux Qt Conifguration
Download CMake 2.8.12 Extract the file, and run "./bootstrap", then "make", then ...
- string.h文件中函数用法
下面为string.h文件中函数的详细用法: strcpy函数名:strcpy功 能: 拷贝一个字符串到另一个用 法: char *strcpy(char *destin, char *source) ...