Spring :2.5.6.SEC01
DWR:2.0.5
我想使用 DWR 中的 session 范围 bean。当我将 bean 配置为单例时,它工作正常。我读了这个导师:
( http://directwebremoting.org/dwr/server/integration/spring.html )
并修改了我的applicationContext.xml,但还是有错误。
我的 applicationContext.xml:
http://pastebin.com/m8d57f18
这很好,但是当我使用 AJAX 函数时,我得到了这个异常:
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.
似乎没有创建 aop 代理,但我不知道为什么。
类路径中的库:
任何的想法? (谢谢!)
最佳答案
为了使 session 或请求范围的 bean 在 Spring 中工作,必须将当前请求和 session 与当前线程相关联。通常,这将由 DispatcherServlet
完成。 ,但如果您不使用它,那么您需要一个替代方案。
这种情况下的替代方案是 RequestContextListener
或 RequestContextFilter
,您可以将其中任何一个连接到您的 web.xml
, 以及允许您使用请求和 session 范围的 bean 的操作系统。只要确保你在 web.xml
中配置它们以便 DWR 请求通过它们。
关于spring - 将 session 范围的 Spring bean 与 DWR 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2138838/