Spring ContextLoaderListener 与 SpringMVC DispatcherServlet所加载的applicationContext的区别
来源:互联网 发布:元符道人淘宝 编辑:程序博客网 时间:2024/05/03 00:16
本篇博客转载自 http://user.qzone.qq.com/413670706/blog/1471574740
Spring通过在web.xml 中配置Listenter : org.springframework.web.context.ContextLoaderListener 来加载spring context配置文件,SpringMVC也可以通过在web.xml 中配置Servlet : org.springframework.web.servlet.DispatcherServlet来加载spring context配置文件,那么这两个有什么区别呢。
ContextLoaderListener加载的spring context配置文件成功后,spring 将 applicationContext存放在ServletContext中key值为"org.springframework.web.context.WebApplicationContext.ROOT"的attribute中。(servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.context));可以通过WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext)或WebApplicationContextUtils.getWebApplicationContext(servletContext)方法来获取对应的applicationContext。
DispatcherServlet加载的spring context配置文件成功后,如果 publishContext属性的值设置为true的话(缺省为true) 会将applicationContext存放在org.springframework.web.servlet.FrameworkServlet.CONTEXT. + (servletName)的attribute中。
ContextLoaderListener加载的spring context配置文件成功后,spring 将 applicationContext存放在ServletContext中key值为"org.springframework.web.context.WebApplicationContext.ROOT"的attribute中。(servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.context));可以通过WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext)或WebApplicationContextUtils.getWebApplicationContext(servletContext)方法来获取对应的applicationContext。
DispatcherServlet加载的spring context配置文件成功后,如果 publishContext属性的值设置为true的话(缺省为true) 会将applicationContext存放在org.springframework.web.servlet.FrameworkServlet.CONTEXT. + (servletName)的attribute中。
则对应的applicationContext的attribute key值为org.springframework.web.servlet.FrameworkServlet.CONTEXT.DispatcherServlet。
在每次request请求时,DispatcherServlet会将此applicationContext存放在request中attribute值为 org.springframework.web.servlet.DispatcherServlet.CONTEXT中(request.setAttribute(WEB_APPLICATION_CONTEXT_ATTRIBUTE,getWebApplicationContext());)。可以通过RequestContextUtils.getWebApplicationContext(servletContext,attrname)或WebApplicationContextUtils.getWebApplicationContext(servletContext,attrname)方法 来获取对应的applicationContext。
在每次request请求时,DispatcherServlet会将此applicationContext存放在request中attribute值为 org.springframework.web.servlet.DispatcherServlet.CONTEXT中(request.setAttribute(WEB_APPLICATION_CONTEXT_ATTRIBUTE,getWebApplicationContext());)。可以通过RequestContextUtils.getWebApplicationContext(servletContext,attrname)或WebApplicationContextUtils.getWebApplicationContext(servletContext,attrname)方法 来获取对应的applicationContext。
解决此问题的方法:在web.xml 中配置Listenter : org.springframework.web.context.ContextLoaderListener 来加载spring context配置文件
0 0
- Spring ContextLoaderListener与DispatcherServlet所加载的applicationContext的区别
- Spring ContextLoaderListener与DispatcherServlet所加载的applicationContext的区别
- Spring ContextLoaderListener与DispatcherServlet所加载的applicationContext的区别
- Spring ContextLoaderListener与DispatcherServlet所加载的applicationContext的区别
- Spring ContextLoaderListener与DispatcherServlet所加载的applicationContext的区别
- Spring ContextLoaderListener与DispatcherServlet所加载的applicationContext的区别
- Spring ContextLoaderListener 与 SpringMVC DispatcherServlet所加载的applicationContext的区别
- ContextLoaderListener与DispatcherServlet所加载的applicationContext的区别
- ContextLoaderListener与DispatcherServlet所加载的applicationContext的区别
- ContextLoaderListener与DispatcherServlet所加载的applicationContext的区别
- [j2ee][spring]ContextLoaderListener与DispatcherServlet所加载的applicationContext的区别
- ContextLoaderListener与DispatcherServlet所加载的区别
- ContextLoaderListener和Spring MVC中的DispatcherServlet加载内容的区别
- spring中ContextLoaderListener和DispatcherServlet区别 ApplicationContext
- Spring中DispatcherServlet和ContextLoaderListener的区别
- Spring中ContextLoaderListener和DispatcherServlet的区别
- Spring 中ContextLoaderListener和DispatcherServlet所加载的context的关系
- DispatcherServlet与ContextLoaderListener的对比
- :before和::before的区别
- 如何搭建sonar
- UVA10071 - Back to High School Physics
- 内省、JavaBean、PropertyDescriptor类、Introspector类、BeanUtils工具包
- android资源空间的区别
- Spring ContextLoaderListener 与 SpringMVC DispatcherServlet所加载的applicationContext的区别
- mysql表名忽略大小写
- 使用EasyUI的datagrid时onLoadSuccess方法执行了两次
- 最大公约数
- 各种Adapter描述
- JSOI2007 祖码Zuma
- 程序员的房事
- protobuf (序列化协议)
- 注解、Rentention、Target、注解的基本属性和高级属性