spring struts2 整合时报Unable to instantiate Action 错
程序员文章站
2022-07-14 19:58:07
...
报错内容为:
其中有一段话为:
然后参考了Spring Framework 2.0.5 API 文档英文版http://doc.javanb.com/spring-framework-api-2-0-5/org/springframework/web/context/request/RequestContextListener.html 才知道项目里的web.xml中没有配置RequestContextListener,则在web.xml中加入下面内容则正常运行了。
Unable to instantiate Action, testAction, defined for 'testStart' in namespace '/TEST'Error creating bean with name 'testAction': 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:307) com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:388) com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:187) org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61) org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39) com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47) org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478) org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
其中有一段话为:
引用
In this case, use RequestContextListener or RequestContextFilter to expose the current request.
然后参考了Spring Framework 2.0.5 API 文档英文版http://doc.javanb.com/spring-framework-api-2-0-5/org/springframework/web/context/request/RequestContextListener.html 才知道项目里的web.xml中没有配置RequestContextListener,则在web.xml中加入下面内容则正常运行了。
<listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener>