spring - 将 session 范围的 Spring bean 与 DWR 一起使用

标签 spring dwr

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 代理,但我不知道为什么。

类路径中的库:
  • 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

  • 任何的想法? (谢谢!)

    最佳答案

    为了使 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/

    相关文章:

    java - 如何为spring-boot jar应用动态添加静态资源?

    Spring 启动2.0.0.M6 : Show all metrics with one request

    java - DWR 传递字符串

    java - Direct Web Remoting (DWR) 是如何工作的?

    java - DWR 如何转换传入数据并规避类型删除

    javascript - DWR,类似于 REST 的 Javascript 库

    java - 如何在Spring中的@Bean方法中定义可选参数(依赖项)?

    Spring 启动 : how to set a common path for multiple RestControllers

    java - Spring Boot 微服务 Intellij Idea