[ 
https://issues.apache.org/struts/browse/WW-2602?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=43663#action_43663
 ] 

Don Brown commented on WW-2602:
-------------------------------

This is because the Struts 2 Spring plugin tries to autowire actions by 
default.  You can either turn that off or add the listener like you suggestion. 
 I'm not sure what else Struts 2 can do here other than have better docs. 

> Struts 2 Spring plugin conflicts with ServletRequestAware
> ---------------------------------------------------------
>
>                 Key: WW-2602
>                 URL: https://issues.apache.org/struts/browse/WW-2602
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Plugin - Spring
>    Affects Versions: 2.1.1
>         Environment: Linux 2.6.24 x86_64, Jetty, Struts 2.1.1-SNAPSHOT, XWork 
> 2.1.1, Spring plugin 2.1.1-SNAPSHOT
>            Reporter: Toni Lyytikäinen
>            Priority: Critical
>         Attachments: Struts2-issue2602.zip
>
>
> If you have an action class that implements the ServletRequestAware interface 
> and has the corresponding setServletRequest method to it, Spring will try to 
> inject a HttpServletRequest into it, causing an exception:
> Unable to instantiate Action, web.MyAction,  defined for 'form' in namespace 
> '/'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.
> Caused by:
> Unable to instantiate Action, web.MyAction,  defined for 'form' in namespace 
> '/'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.
>       at 
> com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:300)
>       at 
> com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:381)
>       at 
> com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:187)
>       at 
> org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:60)
>       at 
> org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:38)
>       at 
> com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47)
>       at 
> org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:466)
>       at 
> org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:458)
>       at 
> org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
>       at 
> org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
>       at 
> org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
>       at 
> org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
>       at 
> org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726)
>       at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
>       at 
> org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:206)
>       at 
> org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
>       at 
> org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
>       at org.mortbay.jetty.Server.handle(Server.java:324)
>       at 
> org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
>       at 
> org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:828)
>       at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514)
>       at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
>       at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
>       at 
> org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
>       at 
> org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:450)
> Caused by: 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.
>       at 
> org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:121)
>       at 
> org.springframework.web.context.support.WebApplicationContextUtils$1.getObject(WebApplicationContextUtils.java:113)
>       at 
> org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:660)
>       at 
> org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:610)
>       at 
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.java:1074)
>       at 
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:980)
>       at 
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:329)
>       at 
> com.opensymphony.xwork2.spring.SpringObjectFactory.autoWireBean(SpringObjectFactory.java:167)
>       at 
> com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:154)
>       at 
> com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:128)
>       at 
> com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:137)
>       at 
> com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:107)
>       at 
> com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:281)
>       ... 24 more
> This can be fixed by adding the following to web.xml:
> <listener>
>    
> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
> </listener>
> But this seems only a workaround and might cause some unwanted side-effects.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to