我在项目中使用了scope="session"和scope="request"
使用的前台是struts但是老是出现错误:
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.后来我在web.xml里加了
<listener>
   <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
不起作用又试了
<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>
还是不起作用
还是那个错误
(就是scope="session"和scope="request"的问题,如果把scope全部改成"singleton"或者"prototype"是没有问题的)

解决方案 »

  1.   

    Spring中bean的scope范围只有两种就是prototype和singleton,分别表示
    多线程调用时实例化多个对象和使用单例
    如果设置成request或者session的话,肯定不匹配相应的schemal或者DTD文件,所以会出现错误
      

  2.   

    spring2.0已经有五种范围了singleton(单例)、non-singleton(也称prototype)、session、request、global session
      

  3.   

    有没人知道,速度。。
    不要说没有session,request
    那是N年前的事了
      

  4.   

    http://jira.springframework.org/browse/SJC-254可能是个BUG
      

  5.   

    RequestContextListener和RequestContextFilter两个类做的都是同样的工作:将HTTP request对象绑定到为该请求提供服务的Thread。这使得具有request和session作用域的bean能够在后面的调用链中被访问到。因此只能用request和session
      

  6.   

    有点看错楼主的意思如果你用RequestContextListener或者RequestContextFilter,则要用的scope是request或者session如果你不用,出现这个错,可能是因为你的bean实例化时是被其他方式实例化的加个<aop:spring-configured>JVM启动参数加上 -javaagent:/{Path}/aspectjweaver.jar,Path是你的jar路径