Using session scoped Spring bean with DWR
Asked Answered
B

2

5

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!)

Bimetallism answered 26/1, 2010 at 10:47 Comment(4)
Are you going through a Spring DispatcherServlet in web.xml?Sensor
yes, when I dont use any ajax feature in the page, it works, like a spring form with controller etc.Bimetallism
No, I mean is the DWR request passing through the DispatcherServlet, or is it going directly to DWR?Sensor
See #2040022Chevet
S
7

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.

Sensor answered 26/1, 2010 at 15:28 Comment(1)
If my web.xml has a spring DispatcherServlet AND a DwrServlet, then the dwr request would pass through the DwrServlet wouldn't it? Oh, and those classes are the "default" classes.. if I want to extend their functionality I'd have to inherit from them right? And if so where would my code go and where would I put the inherited class and how would I link to it? ... On second though I ought to make this a new question ...Heterocercal
F
1

Check if the Session scoped bean is accessed by a global or a singleton. In that case you need to lower the scope of calling bean.

Fidelia answered 30/3, 2011 at 18:8 Comment(3)
Obviously not the answer to this question, but it solved my problem. Thanks.Melone
Or by creating a scoped proxy: @Scope(value="session", proxyMode=ScopedProxyMode.TARGET_CLASS)Lewallen
I think that will require teh RequestContextLisener and the bean have an interface.Tinware

© 2022 - 2024 — McMap. All rights reserved.