struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Peder Larsen (JIRA)" <j...@apache.org>
Subject [jira] Updated: (WW-1576) Spring2 "session" and "request" scopes not working
Date Thu, 28 Dec 2006 00:03:57 GMT
     [ http://issues.apache.org/struts/browse/WW-1576?page=all ]

Peder Larsen updated WW-1576:
-----------------------------

    Description: 
Using spring2 to inject beans on a pr session basis with scope="session" in applicationContext.xml
results in stacktrace. 

I try to inject the bean with this applicationContext.xml,
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans default-autowire="autodetect">
    <bean id="userInfo" class="models.UserInfo" scope="session"></bean>
    <bean id="indexAction" class="actions.IndexAction" scope="request">
    	<property name="userInfo" ref="userInfo" />
    </bean>
</beans>

which results in this stacktrace,
2006-12-27 23:25:35,484 ERROR [StandardContext.java:3638] : Exception starting filter action2
Error creating bean with name 'indexAction': 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? 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. - action - file:/E:/projects/struts2-test/struts2-spring2/target/struts2-spring2-test-2.0.2-SNAPSHOT/WEB-INF/classes/struts.xml:9:44
	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigurationProvider.java:341)
	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:291)
	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:378)
	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:242)
	at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:111)
	at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reload(DefaultConfiguration.java:146)
	at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:52)
	at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:394)
	at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:450)
	at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:213)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:223)
	at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:304)
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:77)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3634)
	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4217)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
	at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
	at org.apache.catalina.core.StandardService.start(StandardService.java:450)
	at org.apache.catalina.core.StandardServer.start(StandardServer.java:709)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:551)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with
name 'indexAction': 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? 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.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:298)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:640)
	at com.opensymphony.xwork2.spring.SpringObjectFactory.getClassInstance(SpringObjectFactory.java:189)
	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigurationProvider.java:328)
	... 27 more
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.AbstractRequestAttributesScope.get(AbstractRequestAttributesScope.java:40)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:279)
	... 31 more
27.des.2006 23:25:35 org.apache.catalina.core.StandardContext start
SEVERE: Error filterStart



  was:Using spring2 to inject beans on a pr session basis with scope="session" in applicationContext.xml
results in stacktrace


I've tried to make this work by adding RequestContextFilter/Listener to my web.xml in any
combination with no luck, a conversition with "mrdon" in struts@irc.freenode.org resulted
in that this needs a patch to work.

So I file the bug here and hopes for a quick patch.

Also i've assembled a simple example that demonstrates this bug, just unzip the ZIP file and
launch it with maven2: mvn jetty:run


> Spring2 "session" and "request" scopes not working
> --------------------------------------------------
>
>                 Key: WW-1576
>                 URL: http://issues.apache.org/struts/browse/WW-1576
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Configuration
>    Affects Versions: 2.0.2
>         Environment: Java 5, Windows Xp
>            Reporter: Peder Larsen
>
> Using spring2 to inject beans on a pr session basis with scope="session" in applicationContext.xml
results in stacktrace. 
> I try to inject the bean with this applicationContext.xml,
> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
> <beans default-autowire="autodetect">
>     <bean id="userInfo" class="models.UserInfo" scope="session"></bean>
>     <bean id="indexAction" class="actions.IndexAction" scope="request">
>     	<property name="userInfo" ref="userInfo" />
>     </bean>
> </beans>
> which results in this stacktrace,
> 2006-12-27 23:25:35,484 ERROR [StandardContext.java:3638] : Exception starting filter
action2
> Error creating bean with name 'indexAction': 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? 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. - action - file:/E:/projects/struts2-test/struts2-spring2/target/struts2-spring2-test-2.0.2-SNAPSHOT/WEB-INF/classes/struts.xml:9:44
> 	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigurationProvider.java:341)
> 	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:291)
> 	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:378)
> 	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:242)
> 	at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:111)
> 	at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reload(DefaultConfiguration.java:146)
> 	at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:52)
> 	at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:394)
> 	at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:450)
> 	at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:213)
> 	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:223)
> 	at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:304)
> 	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:77)
> 	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3634)
> 	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4217)
> 	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
> 	at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
> 	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
> 	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
> 	at org.apache.catalina.core.StandardService.start(StandardService.java:450)
> 	at org.apache.catalina.core.StandardServer.start(StandardServer.java:709)
> 	at org.apache.catalina.startup.Catalina.start(Catalina.java:551)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> 	at java.lang.reflect.Method.invoke(Unknown Source)
> 	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
> 	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)
> Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'indexAction': 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? 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.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:298)
> 	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)
> 	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:640)
> 	at com.opensymphony.xwork2.spring.SpringObjectFactory.getClassInstance(SpringObjectFactory.java:189)
> 	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigurationProvider.java:328)
> 	... 27 more
> 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.AbstractRequestAttributesScope.get(AbstractRequestAttributesScope.java:40)
> 	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:279)
> 	... 31 more
> 27.des.2006 23:25:35 org.apache.catalina.core.StandardContext start
> SEVERE: Error filterStart

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/struts/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message