MockWebServiceClient的可继承线程上下文

时间:2017-01-09 15:14:03

标签: spring spring-mvc

我尝试使用MockWebServiceClient为Web服务运行多线程测试,但这失败了,因为缓存是通过@RequestScope anootation配置请求范围的。

这是我得到的错误:

Wrapped by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.cacheManager': 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.

现在,如果我使用的是MockMvc而不是MockWebServiceClient,我想我可以使用MockMvcBuilders.webAppContextSetup(wac).addFilter(requestContextFilter)并使线程上下文可以继承。

此选项不适用于MockWebServiceClient.createClient(wac)

使用MockWebServiceClient时,是否有办法使线程上下文可继承?或者我的问题有其他解决方案吗?

0 个答案:

没有答案