У меня есть веб-приложение с логикой интеграции Spring, работающей с ним в отдельном потоке. Проблема в том, что в какой-то момент моя логика интеграции Spring пытается использовать bean-компонент запроса, а затем я получаю следующие ошибки:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.tenantContext': 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.
Caused by: 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.
У меня установлен ContextLoaderListener:
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
Мой компонент с областью действия имеет такую аннотацию (поскольку я слышал, что проксирование моего компонента может помочь):
@Component
@Scope(value = "request", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class TenantContext implements Serializable {
Возможно ли то, что я делаю? Если да, то что мне здесь не хватает? Если нет, есть ли другие предложения о том, как я могу этого добиться?