gpt4 book ai didi

java - Spring框架请求范围和单例 Autowiring

转载 作者:行者123 更新时间:2023-11-30 07:33:59 24 4
gpt4 key购买 nike

我将 OncePerRequestFilter 用于自动连接到 Controller 的“请求”范围内的服务 bean。但我仍然收到此错误。

Error creating bean with name 'fileProcessingService': Scope 'request' 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?

请求范围内的 bean 可以注入(inject)单例 bean 吗?或者问题出在其他地方?

最佳答案

如果您需要在 DispatcherServlet 之外使用请求和 session 作用域的 beans,请将以下内容添加到 web.xml:

<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>

关于java - Spring框架请求范围和单例 Autowiring ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5508651/

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