tags:

views:

615

answers:

1

Spring: 2.5.6.SEC01

DWR: 2.0.5

I would like to use a session scoped bean from DWR. It works fine, when I configure the bean to be a singleton. I read this tutor: (http://directwebremoting.org/dwr/server/integration/spring.html) and modified my applicationContext.xml, but it is still wrong somewhere.

My applicationContext.xml:

http://pastebin.com/m8d57f18

It ork well, but when I use an AJAX function, I get this exception:

11:31:09,593 INFO [DefaultRemoter] Exec: DBTestAjaxFunc.testJNDI() 11:31:09,609 WARN [DefaultRemoter] Method execution failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.dbtestajax': 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.

It seems, that the aop proxy wasn't created, but I don't know why.

Libs in the classpath:

  • aspectjrt.jar
  • aspectjweaver.jar
  • cglib-nodep-2.2.jar
  • dwr.jar
  • spring.jar
  • spring-aop.jar
  • spring-dwr-2.0.xsd
  • spring-web.jar
  • spring-webmvc.jar

Any idea? (Thanks!)

+1  A: 

In order for session- or request-scoped beans to work in Spring, something has to associate the current request and session with the current thread. Normally, this would be done by DispatcherServlet, but if you're not using that, then you need an alternative.

The alternative in this case is RequestContextListener or RequestContextFilter, either of which you can wire in to your web.xml, and both os which will allow you to use request- and session-scoped beans. Just make sure that you configure them in web.xml so that DWR requests pass through them.

skaffman