zoukankan      html  css  js  c++  java
  • Scope 'request' is not active for the current thread

    Unable to instantiate Action, getUserAction,  defined for 'getUser' in namespace '/'Error creating bean with name 'getUserAction': Scope 'request' 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:316)
    	com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:397)
    	com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:194)
    	org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
    	org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:37)
    	com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    	org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:552)
    	org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    	org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
    
    将request改为property,不知道为什么会这样
    
    在网上看到有人这样回答
    Scope 'request' is not active for the current thread这句话中说明在某个线程上试图调用scope为request的bean,但是这个bean中能被在http请求线程中实例化,
    简单地说就是:在客户请求的时候才可以被实例化。而我的问题是在服务器启动的时候要实例化,所以有"Scope 'request' is not active for the current thread"
    这一句的出现。在项目中如果有些bean实现了spring中的某些接口(如:SessionAware,RequestAware或BeanPostProcessor等等),就会在服务器启动的时候自动创建代理
    (proxy),这时如果该bean的scope为request、session...这些web作用域的时候就会出现
    consider defining a scoped proxy for this bean if you intend to refer to it from a singleton这句话。
    我的'UserService'这个bean就是间接实现了BeanPostProcessor这个接口,所以一直抛出上面的异常。
    
  • 相关阅读:
    软件工程 2+ 自动生成四则运算题 测试版
    面向对象 (5)计算柱体体积可换底
    面向对象 (4)正方形的周长和面积
    软件工程 3.关于软件质量保障初探
    面向对象 (3)四棱柱的体积与数的判断
    面向对象 (1)矩形的面积和周长
    面向对象 (2)n的阶乘与两点距离
    软件工程 2.20194650 自动生成四则运算题第一版报告
    软件工程 1.《现代软件工程—构建之法》-概论(精读一章有感+练习与讨论部分)
    第四次博客作业-结对项目
  • 原文地址:https://www.cnblogs.com/yan456jie/p/5369564.html
Copyright © 2011-2022 走看看