This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

Testing session scoped beans

Jan 30th, 2009, 07:13 AM

Hi, I'm working on a prototype with a GWT web presentation layer and a spring backend. To connect both I use GWT Server Library. I configured everything with XML and it worked perfectly fine. Since I found out about spring javaconfig i want to use this for configuration. But I get problems with session scoped beans.

On runtime I get the following warning, although communication works later on.:

[WARN] Context initialization failed
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'urlMapping' defined in ServletContext resource [/WEB-INF/benutzerkonto-servlet.xml]: Cannot resolve reference to bean 'serviceBenutzerkonto' while setting bean property 'mappings' with key [TypedStringValue: value [/stammdaten.srv], target type [null]]; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'serviceBenutzerkonto': Scope 'session' 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.

If I remove the session scope, everything is workling withoiut warnings or errors.

Does anybody have an Idea what's going on?

I'm importing in the classpath org.springframework.config.java-1.0.0.M4.jar and org.springframework.config.java-sources-1.0.0.M4.jar plus the files in the lib folder of javaconfig 1.0.0.M3

To get the Tests working with the old XML Configuration I had to extend the AbstractContextLoader, to provide the test with a web Context. If necessary I can also show the code here, but I guess there is a problem with the proxying and I'm probably not using it correct.

OK, I tryed something else. Now I Try to access the session scoped bean from above. Since I want to use the same config in Rich Client without tomcat environment I'll try to create a web context on my own. I found this code:

Comment

Are you aware of JavaConfigWebApplicationContext? Try using that. As for coordinating access to your XML-defined beans, consider using @ImportXml or creating a hierarchical relationship between contexts with sjcContext.setParent(xmlContext);