spring 学习1-Request, session, and global session scopes|(Initial web configuration)
2014-11-05 14:52
447 查看
Initial web configuration
To support the scoping of beans at the request,
session,
and
global sessionlevels
(web-scoped beans), some minor initial configuration is required before you define your beans. (This initial setup is not required for the standard scopes, singleton and prototype.)
How you accomplish this initial setup depends on your particular Servlet environment..
If you access scoped beans within Spring Web MVC, in effect, within a request that is processed by the Spring
DispatcherServlet,
or
DispatcherPortlet,
then no special setup is necessary:
DispatcherServletand
DispatcherPortletalready
expose all relevant state.
If you use a Servlet 2.5 web container, with requests processed outside of Spring’s DispatcherServlet (for example, when using JSF or Struts), you need to register the
org.springframework.web.context.request.RequestContextListener
ServletRequestListener.
For Servlet 3.0+, this can done programmatically via the
WebApplicationInitializerinterface.
Alternatively, or for older containers, add the following declaration to your web application’s
web.xmlfile:
<web-app> ... <listener> <listener-class> org.springframework.web.context.request.RequestContextListener </listener-class> </listener> ... </web-app>
Alternatively, if there are issues with your listener setup, consider the provided
RequestContextFilter.
The filter mapping depends on the surrounding web application configuration, so you have to change it as appropriate.
<web-app> ... <filter> <filter-name>requestContextFilter</filter-name> <filter-class>org.springframework.web.filter.RequestContextFilter</filter-class> </filter> <filter-mapping> <filter-name>requestContextFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> ... </web-app>
DispatcherServlet,
RequestContextListenerand
RequestContextFilterall
do exactly the same thing, namely bind the HTTP request object to the
Threadthat
is servicing that request. This makes beans that are request- and session-scoped available further down the call chain.
相关文章推荐
- 【Spring】Spring IOC原理及源码解析之scope=request、session
- 浅谈Spring学习之request,session与globalSession作用域
- spring学习之springMVC 返回类型选择 以及 SpringMVC中model,modelMap.request,session取值顺序
- spring学习之springMVC 返回类型选择 以及 SpringMVC中model,modelMap.request,session取值顺序
- Spring学习历程---request,session与globalSession作用域
- 【Spring】Spring IOC原理及源码解析之scope=request、session
- spring学习之springMVC 返回类型选择 以及 SpringMVC中model,modelMap.request,session取值顺序
- spring 组件@Scope(request,session)示例
- Spring学习历程---request,session与globalSession作用域
- Spring4.04中实现bean的scope(范围)设置为session或者request
- spring学习之springMVC 返回类型选择 以及 SpringMVC中model,modelMap.request,session取值顺序
- spring 管理action实例 scope="session"
- Scope的几种分类-Session,request,pageflow,view,backingbean
- JSP中page、request、session和application的scope
- Spring获取Session和request
- Struts2学习(六):访问隐藏的request和session
- request.getSession(true) and request.getSession(false)
- 完善GWT官网提出的Spring集成方案(获取HttpServletRequest,session)
- scope取默认,page,request,session,application的区别
- request、session、application学习