You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Niral Trivedi <ni...@gmail.com> on 2008/01/19 07:32:00 UTC

Struts2 and Spring2 with session scoped beans

Hi All,

We've are trying to use Struts2 with Spring2 on Webspher 6.1 and JDK 1.5.
Basically we are trying to use session scoped beans from Spring
applicationContext in to Struts2 using Spring DI. but running in to issue.
Following are my config files:

web.xml
==========================================================================================
 <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <listener>
          <listener-class>
org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
==================================================================================================

Spring applicationContext.xml
==========================================================================================

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="
  http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
  http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean id="mVO" class="com.foo.bar.vo.MyVO" scope="session">
  <aop:scoped-proxy/>
 </bean>
<bean id="myInterceptor" class="com.foo.bar.interceptors.MyInterceptor">
  <property name="mvo">
   <ref local="mVO" />
  </property>
 </bean>
..................
=============================================================================================

When I run this configuration, I am getting following error:
==========================================
[1/18/08 23:49:51:855 EST] 00000032 WebApp        E   [Servlet Error]-[Error
creating bean with name 'scopedTarget.mVO': Scope 'session' 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? 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.]: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'scopedTarget.mVO': Scope 'session' 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? 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: java.lang.IllegalStateException: No thread-bound request found:
Are you 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 case, use
RequestContextListener or RequestContextFilter to expose the current
request.
 at
org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes
(RequestContextHolder.java:102)
 at org.springframework.web.context.request.SessionScope.get(
SessionScope.java:88)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(
AbstractBeanFactory.java:283)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(
AbstractBeanFactory.java:160)
 at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(
SimpleBeanTargetSource.java:33)
 at
org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.getTarget
(Cglib2AopProxy.java:660)
 at
org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept
(Cglib2AopProxy.java:610)
 at com.foo.bar.vo.MyVO$$EnhancerByCGLIB$$d821bb7e.setClassName(<generated>)
 at com.foo.bar.interceptors.MyInterceptor.intercept(MyInterceptor.java:56)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:224)
 at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
DefaultActionInvocation.java:223)
 at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(
UtilTimerStack.java:455)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(
DefaultActionInvocation.java:221)
 at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java
:50)
 at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java
:504)
 at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(
FilterDispatcher.java:419)
 at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(
FilterInstanceWrapper.java:190)
 at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(
WebAppFilterChain.java:130)
 at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(
WebAppFilterChain.java:87)
 at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(
WebAppFilterManager.java:701)
 at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(
WebAppFilterManager.java:646)
 at
com.ibm.ws.webcontainer.extension.DefaultExtensionProcessor.invokeFilters(
DefaultExtensionProcessor.java:628)
 at
com.ibm.ws.wswebcontainer.extension.DefaultExtensionProcessor.invokeFilters(
DefaultExtensionProcessor.java:145)
 at
com.ibm.ws.webcontainer.extension.DefaultExtensionProcessor.handleRequest(
DefaultExtensionProcessor.java:595)
 at
com.ibm.ws.wswebcontainer.extension.DefaultExtensionProcessor.handleRequest(
DefaultExtensionProcessor.java:111)
 at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3129)
 at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:238)
 at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java
:811)
 at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java
:1433)
 at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java
:93)
 at
com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(
HttpInboundLink.java:465)
 at
com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(
HttpInboundLink.java:394)
 at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(
HttpICLReadCallback.java:102)
 at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(
AioReadCompletionListener.java:152)
 at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(
AbstractAsyncFuture.java:213)
 at com.ibm.io.async.AbstractAsyncFuture.fireCompletionActions(
AbstractAsyncFuture.java:195)
 at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
 at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:194)
 at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java
:741)
 at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:863)
 at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1510)
======================================================================================================

As per above error message, I changed web.xml to have
org.springframework.web.context.request.RequestContextListener instead of
ContextLoaderListener but that cause Struts2 to fail with following error:
==================================================================================================================================================

[1/19/08 0:54:47:605 EST] 00000032 StrutsSpringO E
org.apache.commons.logging.impl.Jdk14Logger fatal ********** FATAL ERROR
STARTING UP STRUTS-SPRING INTEGRATION **********
Looks like the Spring listener was not configured for your web app!
Nothing will work until WebApplicationContextUtils returns a valid
ApplicationContext.
You might need to add the following to web.xml:
    <listener>
        <listener-class>
org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

===================================================================================================

So, not sure what am I missing here. Is it a case that, Spring wants us to
use RequestContextListener for session scoped beans but Struts2-spring
plugin will not allow us to use other than ContextLoaderListener.

I tried old mailing list archives and did search on google but could not
find any solution to this problem.

So, please help me here.

Thanks in advance..

Re: Struts2 and Spring2 with session scoped beans

Posted by Dave Newton <ne...@yahoo.com>.
See my reply to your first message.

d.

--- Niral Trivedi <ni...@gmail.com> wrote:

> Hi All,
> 
> We've are trying to use Struts2 with Spring2 on Webspher 6.1 and JDK 1.5.
> Basically we are trying to use session scoped beans from Spring
> applicationContext in to Struts2 using Spring DI. but running in to issue.
> Following are my config files:
> 
> web.xml
>
==========================================================================================
>  <filter>
>         <filter-name>struts2</filter-name>
>         <filter-class>org.apache.struts2.dispatcher.FilterDispatcher
> </filter-class>
>     </filter>
>     <filter-mapping>
>         <filter-name>struts2</filter-name>
>         <url-pattern>/*</url-pattern>
>     </filter-mapping>
> 
>     <listener>
>           <listener-class>
> org.springframework.web.context.ContextLoaderListener</listener-class>
>     </listener>
>
==================================================================================================
> 
> Spring applicationContext.xml
>
==========================================================================================
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
>        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>        xmlns:aop="http://www.springframework.org/schema/aop"
>        xsi:schemaLocation="
>   http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
>   http://www.springframework.org/schema/aop
> http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
> <bean id="mVO" class="com.foo.bar.vo.MyVO" scope="session">
>   <aop:scoped-proxy/>
>  </bean>
> <bean id="myInterceptor" class="com.foo.bar.interceptors.MyInterceptor">
>   <property name="mvo">
>    <ref local="mVO" />
>   </property>
>  </bean>
> ..................
>
=============================================================================================
> 
> When I run this configuration, I am getting following error:
> ==========================================
> [1/18/08 23:49:51:855 EST] 00000032 WebApp        E   [Servlet
> Error]-[Error
> creating bean with name 'scopedTarget.mVO': Scope 'session' 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? 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.]: org.springframework.beans.factory.BeanCreationException:
> Error creating bean with name 'scopedTarget.mVO': Scope 'session' 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? 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: java.lang.IllegalStateException: No thread-bound request found:
> Are you 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 case, use
> RequestContextListener or RequestContextFilter to expose the current
> request.
>  at
>
org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes
> (RequestContextHolder.java:102)
>  at org.springframework.web.context.request.SessionScope.get(
> SessionScope.java:88)
>  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(
> AbstractBeanFactory.java:283)
>  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(
> AbstractBeanFactory.java:160)
>  at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(
> SimpleBeanTargetSource.java:33)
>  at
>
org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.getTarget
> (Cglib2AopProxy.java:660)
>  at
>
org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept
> (Cglib2AopProxy.java:610)
>  at
> com.foo.bar.vo.MyVO$$EnhancerByCGLIB$$d821bb7e.setClassName(<generated>)
>  at com.foo.bar.interceptors.MyInterceptor.intercept(MyInterceptor.java:56)
>  at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
> DefaultActionInvocation.java:224)
>  at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
> DefaultActionInvocation.java:223)
>  at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(
> UtilTimerStack.java:455)
>  at com.opensymphony.xwork2.DefaultActionInvocation.invoke(
> DefaultActionInvocation.java:221)
>  at
> org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java
> :50)
>  at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java
> :504)
>  at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(
> FilterDispatcher.java:419)
>  at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(
> FilterInstanceWrapper.java:190)
>  at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(
> WebAppFilterChain.java:130)
>  at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(
> WebAppFilterChain.java:87)
>  at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(
> WebAppFilterManager.java:701)
>  at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(
> WebAppFilterManager.java:646)
>  at
> com.ibm.ws.webcontainer.extension.DefaultExtensionProcessor.invokeFilters(
> DefaultExtensionProcessor.java:628)
>  at
>
com.ibm.ws.wswebcontainer.extension.DefaultExtensionProcessor.invokeFilters(
> DefaultExtensionProcessor.java:145)
>  at
> com.ibm.ws.webcontainer.extension.DefaultExtensionProcessor.handleRequest(
> DefaultExtensionProcessor.java:595)
>  at
>
com.ibm.ws.wswebcontainer.extension.DefaultExtensionProcessor.handleRequest(
> DefaultExtensionProcessor.java:111)
>  at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3129)
>  at
> com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:238)
>  at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java
> :811)
>  at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java
> :1433)
>  at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java
> :93)
>  at
> com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(
> HttpInboundLink.java:465)
>  at
> com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(
> HttpInboundLink.java:394)
>  at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(
> HttpICLReadCallback.java:102)
>  at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(
> AioReadCompletionListener.java:152)
>  at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(
> AbstractAsyncFuture.java:213)
>  at com.ibm.io.async.AbstractAsyncFuture.fireCompletionActions(
> AbstractAsyncFuture.java:195)
>  at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
>  at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:194)
>  at
> com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java
> :741)
>  at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:863)
>  at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1510)
>
======================================================================================================
> 
> As per above error message, I changed web.xml to have
> org.springframework.web.context.request.RequestContextListener instead of
> ContextLoaderListener but that cause Struts2 to fail with following error:
>
==================================================================================================================================================
> 
> [1/19/08 0:54:47:605 EST] 00000032 StrutsSpringO E
> org.apache.commons.logging.impl.Jdk14Logger fatal ********** FATAL ERROR
> STARTING UP STRUTS-SPRING INTEGRATION **********
> Looks like the Spring listener was not configured for your web app!
> Nothing will work until WebApplicationContextUtils returns a valid
> ApplicationContext.
> You might need to add the following to web.xml:
>     <listener>
>         <listener-class>
> org.springframework.web.context.ContextLoaderListener</listener-class>
>     </listener>
> 
>
===================================================================================================
> 
> So, not sure what am I missing here. Is it a case that, Spring wants us to
> use RequestContextListener for session scoped beans but Struts2-spring
> plugin will not allow us to use other than ContextLoaderListener.
> 
> I tried old mailing list archives and did search on google but could not
> find any solution to this problem.
> 
> So, please help me here.
> 
> Thanks in advance..
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org