我们的项目有批处理过程,计划在服务器启动时运行,然后每24小时运行一次。下面是spring文件中的配置。
<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>
此批处理过程的作用是,它从批处理表中获取所有要续订的策略并进行更新。 采取每个策略,然后调用更新过程。在更新过程中,我们使用一个名为“location”的bean,它的作用域为session。以下是定义。
<bean id="location" class="com.mindtree.ruc.cmn.utils.LoginLocation" scope="session">
<aop:scoped-proxy/>
</bean>
我们不使用dispatcherservlet,但我们使用下面定义的上下文监听器(在web.xml中):
<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定义为会话/请求范围的地方,但我们在服务器启动期间使用这些bean(还没有会话或请求),怎么回事,spring不会抛出异常?
答案 0 :(得分:1)
你的POM有:
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>3.1</version>
</dependency>
有很多事情,如果您正在做这一切,请参阅下面的帖子: