tags:

views:

24

answers:

2

I'm adding some features to an old EJB 2 application using Spring. The Spring application context used by the EJBs is a parent context of the web application as described here.

I'm trying to use a session scoped bean from within the EJBs. The bean in question is initialized from the EJB application context.

However, I get this error when trying to access the bean:

Caused by: java.lang.IllegalStateException: No Scope registered for scope 'session'

From what I've read, this is because the parentContextKey is not an instance of WebApplicationContext. Does anyone have an ideas of how I could get this working?

A: 

You can only use session-scoped Spring beans from within a Spring WebApplicationContext. There's no getting around this - no WebApplicationContext, no session-scoping.

Perhaps if you explained what you're trying to achieve, we could help further. Are you perhaps conflating stateful session EJBs with servlet sessions? They're not the same thing.

skaffman
+1  A: 

You may try to register the scope manually:

<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
    <property name="scopes">
        <map>
            <entry key="thread">
                <bean class="org.springframework.web.context.request.SessionScope"/>
            </entry>
        </map>
    </property>
</bean>

I guess it should work, because SessionScope itself depends only on the thread-bound request context exposed by the RequestContextListener and doesn't depend on the application context.

axtavt
Exactly what I needed. Thanks!
Jason Gritman