当前位置: 首页 > 知识库问答 >
问题:

无法理解:“作用域'session'对当前线程不是活动的”

马欣荣
2023-03-14
<bean id="RenewalBatchSvc" class="com.rsaame.pas.renewals.scheduler.RenewalBatchService" >
    <property name="renewalBatchSchedulerSvc" ref="RenewalBatchSchedulerSvc" />
</bean>

<bean id="RenewalBatchScheduledTask" class="org.springframework.scheduling.timer.ScheduledTimerTask"> 
    <!-- wait 20 seconds before starting repeated execution -->
    <property name="delay" value="20000" />
    <!-- run every 24 hrs 86400000-->
    <property name="period" value="86400000" />
    <property name="timerTask" ref="RenewalBatchSvc" />
</bean>

<bean id="RenewalBatchTimerFactory" class="org.springframework.scheduling.timer.TimerFactoryBean">
    <property name="scheduledTimerTasks">
        <list>              
             <ref bean="RenewalBatchScheduledTask" />   
        </list>
    </property>
</bean>         
<bean id="location" class="com.mindtree.ruc.cmn.utils.LoginLocation" scope="session">
    <aop:scoped-proxy/>
</bean>
<listener>
    <listener-class>
        org.springframework.web.context.request.RequestContextListener
    </listener-class>
</listener>
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.location': 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, or processing a request outside of the originally receiving thread? 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.doGetBean(AbstractBeanFactory.java:341)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
    at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:33)
    at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.getTarget(Cglib2AopProxy.java:653)
    at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:604)
    at com.mindtree.ruc.cmn.utils.LoginLocation$$EnhancerByCGLIB$$db19ad5f.getLocation(<generated>)
    at com.mindtree.ruc.cmn.utils.LocationHandler.getLocation(LocationHandler.java:17)
    at com.mindtree.ruc.cmn.utils.Utils.getSingleValueAppConfig(Utils.java:707)

当批处理在服务器启动时运行时不会出现上述异常。但只有在24小时后调用批处理时才会发生。为什么会这样?如果出现异常,那么即使批处理在(IBM websphere)服务器启动时运行,也应该出现异常。为什么会话在服务器启动时可用,甚至在应用程序完全启动之前,没有人使用它?

在我们将bean定义为会话/请求范围的地方,但我们在服务器启动期间使用这些beans(还没有发出会话或请求),为什么spring不会抛出异常?

共有1个答案

梁丘翔
2023-03-14

您的POM是否有:

 <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>3.1</version>
    </dependency>

有很多事情,如果你都在做,请看下面的帖子:

作用域“会话”对于当前线程不是活动的;IllegalStateException:未找到线程绑定请求

 类似资料: