我有一个 Web 应用程序,其中我使用 ScheduledThreadPoolExecutor 来安排一些稍后执行的逻辑(可能在原始 Web 请求结束后)。是否可以在子线程内访问/使用原始请求的 HttpServletRequest(通过 ScheduledThreadPoolExecutor 上的“schedule”调用创建)?
我尝试在其函数在子线程中运行的类中 Autowiring HttpServletRequest,但出现以下错误(我了解原因)
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.
有什么可行的办法吗?可以RequestContextFilter可能会被使用吗?
我是一名优秀的程序员,十分优秀!