gpt4 book ai didi

java - 在没有 session 的情况下使用 Spring session 范围

转载 作者:太空宇宙 更新时间:2023-11-04 13:32:25 24 4
gpt4 key购买 nike

我有一个 Web 应用程序,我在其中定义了 session 范围的 UserDetail。问题是我还有一些应该使用 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.

在工作内部,我需要注入(inject)一些“技术用户”详细信息。是否可以正确处理 session 不存在的情况?也许有条件注入(inject)?

编辑 1

澄清一下。我不想在我的工作服务中进行 session 。该作业修改数据,并将一些基于用户数据的审核日志保存到数据库中。通常用户数据来自 session ,但在工作中我需要提供一些“静态”技术用户数据。有什么想法吗?

最佳答案

Quartz 对“ session ”一无所知,因此,如果您希望后台作业了解提交作业的用户,必须将该信息传递给作业,可能在触发器的 DataMap 中。

关于java - 在没有 session 的情况下使用 Spring session 范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32043323/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com