WebSphere6.x中不能使用Spring的session scope注入对象的解决办

本文记录了一次使用Spring AOP注入SessionScope对象时遇到的问题及解决过程。主要异常为Session作用域未激活导致无法获取到目标bean。通过将RequestContextListener替换为RequestContextFilter解决了问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


原来一直使用spring的aop去注入一些Session scope的对象,但是今天在部署此类应用程序的时候却出现了以下异常:
[09-12-25 14:50:52:562 CST] 0000003f WebApp E SRVE0026E: [Servlet ERROR]-[Filter [IdentityFilter]: filter is unavailable.]:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.sessionUser': 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:285)
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:661)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:611)
at com.interprosoft.maximo.maximostudy.user.module.User$$EnhancerByCGLIB$$64b912.toString(<generated>)
at java.lang.String.valueOf(String.java(Inlined Compiled Code))
at java.lang.StringBuffer.append(StringBuffer.java(Compiled Code))
...
查了半天资料,也没有人给出解决办法,没办法了,有把spring的文档找来看看了,最后把web.xml文件中使用的Listener换成Filter就把问题解决了,就是把
<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>

但是具体原因还是没有搞清楚,等以后有时间再好好看看。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值