In spring, I have a lot of code that uses session beans defined like this:
@Scope(value="session", proxyMode=ScopedProxyMode.TARGET_CLASS)
-
In my webapplication all is fine, since a session scope is
available. -
In my JUnit tests, all is also fine since i’m using a
WebContextTestExecutionListener(link) that registers a thread
scope for the session scope -
But when a method with
@Scheduledis called, I get an exception since there is no
session scope.
Now my question is: How can I register a thread scope for the session scope in my @Scheduled method?
I have tried something like this: beanFactory.registerScope("session", new SimpleThreadScope()); but that also overrides the session scope of my webapplication 🙁
It turned out, this question is very much related to: spring 3 scheduled task running 3 times. Since my ContextLoaderListener and DispatcherServlet were pointing at the same context config, the scopes got overridden.
@skaffman/Wesley: Thanks for your comments.