我有一个 Web 应用程序,我在其中使用 ScheduledThreadPoolExecutor 来安排稍后执行的一些逻辑(可能在原始 Web 请求结束之后)。是否可以在子线程内访问/使用原始请求的 HttpServletRequest(通过 ScheduledThreadPoolExecutor 上的“schedule”调用创建)?
我尝试在其函数在子线程中运行的类中自动装配 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吗?