将会话范围的 Spring bean 与 DWR 结合使用

发布于 2024-08-19 08:43:04 字数 1351 浏览 6 评论 0 原文

Spring:2.5.6.SEC01

DWR:2.0.5

我想使用 DWR 中的会话范围 bean。当我将 bean 配置为单例时,它工作得很好。我读过这个导师: (http://directwebremoting.org/dwr/server/integration/spring.html) 并修改了我的applicationContext.xml,但它仍然是错误的地方。

我的 applicationContext.xml:

http://pastebin.com/m8d57f18

效果很好,但是当我使用 AJAX 函数时,我得到这个异常:

11:31:09,593 信息 [默认远程] 执行:DBTestAjaxFunc.testJNDI() 11:31:09,609 警告 [默认远程] 方法执行失败: org.springframework.beans.factory.BeanCreationException: 使用名称创建 bean 时出错 'scopedTarget.dbtestajax':范围 “会话”未处于活动状态 当前线程;考虑定义一个 如果您有此 bean 的作用域代理 打算从一个参考它 单例;嵌套异常是 java.lang.IllegalStateException:否 发现线程绑定请求:你是吗 参考请求属性 在实际的网络请求之外,或者 处理外部请求 最初接收线程?如果你 实际上是在网络中运行的 请求并仍然收到此消息 消息,您的代码可能正在运行 之外 DispatcherServlet/DispatcherPortlet: 在这种情况下,使用 RequestContextListener 或 RequestContextFilter 公开 当前请求。

看来 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

有什么想法吗? (谢谢!)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦冥 2024-08-26 08:43:04

为了使会话范围或请求范围的 bean 在 Spring 中工作,必须将当前请求和会话与当前线程关联起来。通常,这将由 DispatcherServlet 完成,但如果您不使用它,那么您需要一个替代方案。

这种情况下的替代方案是 RequestContextListenerRequestContextFilter,您可以将其中一个连接到您的 web.xml,并且两个操作系统都允许您使用 request - 和会话范围的 bean。只需确保在 web.xml 中配置它们,以便 DWR 请求通过它们。

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.

你是我的挚爱i 2024-08-26 08:43:04

检查会话作用域 bean 是否由全局或单例访问。在这种情况下,您需要降低调用 bean 的范围。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文