2015-08-17 49 views
1

我有定义会话范围UserDetail的Web应用程序。问题是我也有一些应该使用UserDetail bean的Quartz作业。工作时,我得到:在没有会话的情况下使用弹簧会话范围

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.userDetails': 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. 

内部工作我需要注入一些“技术用户”的细节。会话不存在时能否妥善处理情况?也许有条件注射?

EDIT 1

为了阐明。我不想在我的工作服务会议。这项工作修改了数据,一些基于用户数据的审计日志被保存到数据库中。通常用户数据来自会话,但在作业中,我需要提供一些“静态”技术用户数据。有任何想法吗?

+0

你试图将会话范围的bean注入单例bean吗? –

+1

会话仅存在于Web应用程序中,并且当存在活动会话时,因此不会有会话未激活的会话。在我看来,你正在接近它错... –

+0

我想运行工作时有单身豆。 – lbednaszynski

回答

0

石英对“会话”一无所知,所以如果你希望你的后台作业知道提交作业的用户,那么you必须将该信息传递给作业,可能在触发器的DataMap中。

相关问题