我正在将 OncePerRequestFilter 用于“请求”范围内的服务 bean,该服务 bean 自动连接到 Controller 中。但我仍然收到此错误。
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 可以用单例 bean 注入(inject)吗?或者问题出在其他地方?
最佳答案
如果您需要在 DispatcherServlet
之外使用请求和 session 范围的 Bean,请将以下内容添加到 web.xml
中:
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
关于java - Spring框架请求范围和单例 Autowiring ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5508651/