1

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?

Community
  • 1
  • 1
Sleeper9
  • 1,707
  • 1
  • 19
  • 26
  • Add `proxyMode=INTERFACES` to the `@Scope` annotation. Without it the default is to create no scoped proxy leading to the exception you have. – M. Deinum Jan 14 '16 at 10:24
  • Tried that, it did not help; I debugged right into Spring's `RequestContextListener` class, and even the `requestInitialized()` method does not get called. It seems like Tomee does not register the listener at all. – Sleeper9 Jan 14 '16 at 10:41
  • When do you get this exception (assumption was at startup!). – M. Deinum Jan 14 '16 at 10:53
  • I get this exception when I access a page that has a controller with Spring beans injected. In particular, I use Stripes framework with Spring integration. So it is occuring when a request has been fired and the DI is just about to happen. – Sleeper9 Jan 14 '16 at 11:39
  • DI should already be done at startup also for the scoped proxies. Looks like you have more listeners and in that case the ordering is important... – M. Deinum Jan 14 '16 at 11:43
  • I see, but this configuration works flawlessly on Tomcat 7,8 and Glassfish 4 environments, so that's why I think it's related to Tomee 7.0.0. I have a struggle with trying this on the latest stable Tomee 1.7.3 though, but that's because of some conflict between our libs and the Tomee libs. – Sleeper9 Jan 14 '16 at 13:18

0 Answers0