您的位置:首页 > 运维架构

Scope 'session' is not active for the current thread

2012-12-03 14:17 621 查看

1、问题一

用struts2做查询,当不同客户端查询时,a端会看到b端的查询结果,导致原因scope="singleton"

解决方法:

要将bean中的scope设置成“session【session作用域的bean则对每次http Session有效】

<bean id="assetAction" class="com.servicezone.itsd.asset.webapp.action.AssetAction"scope="session">

<property name="assetManager" ref="assetManager"/>

<property name="itProductManager" ref="itProductManager"/>

<property name="vendorManager" ref="vendorManager"/>
</bean>”
于是出现如下异常

2、问题二

Struts Problem Report

Struts has detected an unhandled exception:

Messages:No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message,
your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
Error creating bean with name 'qAction': Scope 'session' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound
request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably
running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
Unable to instantiate Action, qAction, defined for 'qshow' in namespace '/'Error creating bean with name 'qAction': Scope 'session' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a
singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually
operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.

File:org/springframework/web/context/request/RequestContextHolder.java
Line number:131

Stacktraces

Unable to instantiate Action, qAction, defined for 'qshow' in namespace '/'Error creating bean with name 'qAction':Scope 'session' is not active for the current thread;consider
defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing
a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener
or RequestContextFilter to expose the current request.


com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:318)
    com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:399)

解决方法

(1)当使用了Spring's DispatcherServlet以外的Servlet 2.4及以上的Web容器时(如使用JSF或Struts),你需要在Web应用的'web.xml'文件中增加 javax.servlet.ServletRequestListener 定义
<web-app>
  ...
  <listener>

<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>

</listener> ... </web-app>

(2)如果你用的是早期版本的web容器(Servlet 2.4以前的版本),那么你要使用一个javax.servlet.Filter的实现。请看下面的web.xml配置片段:

<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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐