Hello.  I am in the process of migrating my application from webwork
2.2.x to Struts 2 and have encountered a problem.  I have a custom
interceptor which has a member variable injected by Spring.  This
object is a request scoped bean which is contructed using a factory
method from another bean which is a singleton.  So, it looks like
something like this:


MyInterceptor
-->private RequestBasedBean rbb
--> @required
    void setRequestBasedBean


in applicationContext.xml:

 <bean id="factory" class="com.blah.mypackage.myclass" scope="singleton">
   <bunch of stuff here>
 </bean>

 <bean id="sessionFactory" factory-bean="factory" factory-method="getFactory"
     scope="singleton"/>

 <bean id="requestBasedBean" factory-bean="sessionFactory"
factory-method="openSession"  destroy-method="close" scope="request"
/>


This worked fine in webwork, but in struts 2, it looks like it is
trying to construct MyInterceptor at startup time and failing because
when it injects the requestBaseBean, there is no request context and
it fails (Stack trace below).  Note that I am using a request-scoped
bean and it is sort of referred to by a singleton, but I don't think I
need to use a scoped-proxy (which fails anyways, I tried it).  Again,
this worked fine in the WebWork implementation.  So, I'm trying to see

a) what changed with struts 2 interceptor intialization.
b) if it isn't technically a struts 2 problem, what workaround exist
in Spring (I may take this to the spring forums if this is not an
issue around struts 2).

Thanks!  And there is a reason why there are all the singletons and
factory stuff.  Related to legacy support and non-spring aware code.

-Steve


Caused by: org.springframework.beans.factory.BeanCreationException: Error creati
ng bean with name 'requestBasedBean': 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 thre
ad-bound request found: Are you referring to request attributes outside of an ac
tual web request? If you are actually operating within a web request and still r
eceive this message,your code is probably running outside of DispatcherServlet/D
ispatcherPortlet: In this case, use RequestContextListener or RequestContextFilt
er to expose the current request.
       at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
(AbstractBeanFactory.java:304)
       at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
(AbstractBeanFactory.java:160)
       at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.autowireByName(AbstractAutowireCapableBeanFactory.java:880)
       at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.populateBean(AbstractAutowireCapableBeanFactory.java:828)
       at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:273)
       at com.opensymphony.xwork2.spring.SpringObjectFactory.autoWireBean(Sprin
gObjectFactory.java:167)
       at com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringOb
jectFactory.java:154)
       at com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringOb
jectFactory.java:128)
       at com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:14
3)
       at com.opensymphony.xwork2.ObjectFactory.buildInterceptor(ObjectFactory.
java:184)
       ... 52 more
Caused by: java.lang.IllegalStateException: No thread-bound request found: Are y
ou referring to request attributes outside of an actual web request? 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 cas
e, use RequestContextListener or RequestContextFilter to expose the current requ
est.
       at org.springframework.web.context.request.RequestContextHolder.currentR
equestAttributes(RequestContextHolder.java:102)
       at org.springframework.web.context.request.AbstractRequestAttributesScop
e.get(AbstractRequestAttributesScope.java:40)
       at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
(AbstractBeanFactory.java:285)
       ... 61 more

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to