在我的应用程序中,我有一些异步Web服务。服务器接受请求,返回OK响应并使用AsyncTaskExecutor启动处理请求。我的问题是如何在此处启用请求范围,因为在此处理中我需要获取注释的类:
@Scope(value = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.TARGET_CLASS)
现在我得到例外:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.requestContextImpl': 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? 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.
因为它运行SimpleAsyncTaskExecutor而不是运行DispatcherServlet
我的异步处理请求
taskExecutor.execute(new Runnable() {
@Override
public void run() {
asyncRequest(request);
}
});
taskExecutor的位置是:
<bean id="taskExecutor" class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
小唯快跑啊
相关分类