I am currently running an application with Apache Tomee 7.0.0-M1 release. I am using Spring 3.2.6 and I'd like to use request-scoped service beans managed by Spring. I've read the documentation that for this, I have to add these to web.xml
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
I've annotated my services like this:
@Service
@Scope(value = org.springframework.web.context.WebApplicationContext.SCOPE_REQUEST)
@Transactional
public class RCService implements IRCService { ... }
The problem is, I get an exception like this:
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 ...
The same problem has been asked in this post, but as I said, I already put the necessary listener in my web.xml
. Is this currently a problem/bug with Tomee, or I am missing something?