1

我目前正在使用Apache Tomee 7.0.0-M1版本运行应用程序。我正在使用Spring 3.2.6,我想使用由 Spring 管理的请求范围的服务 bean。我已经阅读了为此的文档,我必须将这些添加到web.xml

<listener>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>

我已经这样注释了我的服务:

@Service
@Scope(value = org.springframework.web.context.WebApplicationContext.SCOPE_REQUEST)
@Transactional
public class RCService implements IRCService { ... }

问题是,我得到一个这样的异常:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xyz': 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.
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:312)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
        at ...

这篇文章中也提出了同样的问题,但正如我所说,我已经在我的web.xml. 这是目前 Tomee 的问题/错误,还是我遗漏了什么?

4

0 回答 0