spring bean 的scope问题 scope更改为session后出现异常
spring2.0+struts2+hibernate3.1
tomcat6.0+jdk1.6
使用springIOC时
<bean id="userAction" class="com.wc.action.UserAction" scope="session">
<property name="userbiz">
<ref bean="UserBiz"/>
</property>
</bean>
并且在web.xml中加入
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
出现异常,尝试用这种配置
<filter> <filter-name>requestContextFilter</filter-name> <filter-class>org.springframework.web.filter.RequestContextFilter</filter-class></filter> <filter-mapping> <filter-name>requestContextFilter</filter-name> <url-pattern>/*</url-pattern></filter-mapping>
还是出现异常。
为什么呢?
用prototype或者默认的singleton都可以实现功能,但是现在遇到的这个问题让我不解,想知道怎么会出现这样的异常呢,按理论来讲是不应该出现的啊。org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userAction': 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.......
一般直接有prototype就是行了
没碰到过这种需求,一般问题用默认的就可以解决。