Wednesday, February 6, 2013

Simple session and request scopes for spring unit tests

I've ran into this several times before and today it happened again. You get a message like this

java.lang.IllegalStateException: No Scope registered for scope ‘session’

when running spring managed unit tests on your spring managed beans.


I remember having created a complex solution the last time for this issue. But today I found this blog entry. What you do is to register
org.springframework.context.support.SimpleThreadScope  
for the session and request scope using the
org.springframework.beans.factory.config.CustomScopeConfigurer 
bean. The technical details are outlined in the blog post, you can read that entry for yourselves. This solution is much more pretty than my old one that you can find in some of my old sources on github. The original idea comes from here, but that blog seems to be borken.

No comments:

Post a Comment