解决Scope 'request' is not active for the current thread异常
2014-03-13 21:47
881 查看
在spring整合struts中,spring配置文件中的action bean一定要配置scope属性,因为每次请求的信息包含在action中
<bean id="loginAction" class="com.wzy.app.action.LoginAction" scope="request">
<property name="myService" ref="myService" />
</bean>
但是这会抛出一个异常:Scope 'request' is not active for the current thread
百度一下,大概的解释是:
要使用request、session和 global session作用域的bean(即具有web作用域的bean), 在开始设置bean定义之前,还要做少量的初始配置。请注意,假如你只想要“常规的”作用域,(singleton和prototype),就不需要这一额外的设置。
在目前的情况下,根据你的特定servlet环境,有多种方法来完成这一初始设置...
如果你用Spring Web MVC,即用SpringDispatcherServlet或DispatcherPortlet来处理请求,则不需要做特别的配置:DispatcherServlet 和 DispatcherPortlet已经处理了所有有关的状态
当使用了Spring's DispatcherServlet以外的Servlet 2.4及以上的Web容器时(如使用JSF或Struts),你需要在Web应用的'web.xml'文件中增加 javax.servlet.ServletRequestListener 定义
在web.xml中添加定义
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>针对servlet2.4以及之前版本的情况,使用Filter配置如下:
<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>
RequestContextListener和RequestContextFilter两个类做的都是同样的工作: 将HTTP request对象绑定到为该请求提供服务的Thread。 这使得具有request和session作用域的bean能够在后面的调用链中被访问到。
<bean id="loginAction" class="com.wzy.app.action.LoginAction" scope="request">
<property name="myService" ref="myService" />
</bean>
但是这会抛出一个异常:Scope 'request' is not active for the current thread
百度一下,大概的解释是:
要使用request、session和 global session作用域的bean(即具有web作用域的bean), 在开始设置bean定义之前,还要做少量的初始配置。请注意,假如你只想要“常规的”作用域,(singleton和prototype),就不需要这一额外的设置。
在目前的情况下,根据你的特定servlet环境,有多种方法来完成这一初始设置...
如果你用Spring Web MVC,即用SpringDispatcherServlet或DispatcherPortlet来处理请求,则不需要做特别的配置:DispatcherServlet 和 DispatcherPortlet已经处理了所有有关的状态
当使用了Spring's DispatcherServlet以外的Servlet 2.4及以上的Web容器时(如使用JSF或Struts),你需要在Web应用的'web.xml'文件中增加 javax.servlet.ServletRequestListener 定义
在web.xml中添加定义
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>针对servlet2.4以及之前版本的情况,使用Filter配置如下:
<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>
RequestContextListener和RequestContextFilter两个类做的都是同样的工作: 将HTTP request对象绑定到为该请求提供服务的Thread。 这使得具有request和session作用域的bean能够在后面的调用链中被访问到。
相关文章推荐
- org.springframework.beans.factory.BeanCreationException: Scope 'request' is not active for the current thread
- 关于Scope 'session' is not active for the current thread的问题
- Scope 'session' is not active for the current thread
- Spring报错——Scope 'session' is not active for the current thread
- getCurrentSession()抛出is not valid without active transaction和no session found for current thread异常分析
- 非常牛叉的楼主,自己的问题其实就是答案--用springmvc上传文件时报The current request is not a multipart request异常
- 解决The current branch is not configured for pull No value for key branch.master.
- maven 上传解决The current branch is not configured for pull No value for key branch.master.merge found i
- 已解决:The current branch is not configured for pull No value for key ...(for eclipse)
- 解决The current branch is not configured for pull No value for key branch.master.merge found in config
- git 解决The current branch is not configured for pull No value for key branch.master.merge found in co
- The current request is not a multipart request异常
- 解决The current branch is not configured for pull No value for key branch.master.merge found in confi
- 解决The current branch is not configured for pull No value for key branch.master.m
- 解决The current branch is not configured for pull No value for key branch.master.merge found in config
- git:解决The current branch is not configured for pull No value for key branch.master.merge found in config
- SpringMVC异常:org.springframework.web.multipart.MultipartException: The current request is not a multi
- 解决The current branch is not configured for pull No value for key branch.master.merge found in config
- (git问题)解决The current branch is not configured for pull No value for key remote.origin
- 解决springMVC文件上传报错: The current request is not a multipart request