DWR Spring 集成:是否可以将 DWR 请求转发到 Spring 控制器?
我有一个集成了 DWR 3 和 Spring 3 的 Web 应用程序。所有请求都由 Spring 的 DispatcherServlet 处理。一切正常。当我请求 AJAX 请求时,用 @RemoteProxy 注释的支持 DWR 服务 bean 会正确处理它。为了返回响应,我的 DWR 服务 bean 返回包含 @DataTransferObject POJO 的 HTML 字符串或仅返回普通 POJO。
我想要做的是在 DWR 服务 bean 中,我希望它将处理转发给 Spring @Controller bean。 AJAX 请求仍将由 DWR 服务处理,但真正的处理委托给 Spring 控制器 bean。换句话说,DWR 服务 bean 只是实际服务的服务外观。这样我就不会重复逻辑。
这可能吗?
让我进一步澄清。
在普通的非 AJAX 应用程序中,当用户提交表单时,会发生以下情况:
- 它被转发到 DispatcherServlet
- 然后是一个 @Controller 注解的 bean。
- 然后由@Service bean 进行处理。
- 之后,控制器返回一个 ModelAndView。
在 DWR-AJAX 应用程序中,当用户提交表单时,会发生以下情况:
- 它仍然转发到 DispatcherServlet 然后
- 转发到带注释的 @RemoteProxy 豆。处理由 这颗豆子。这就是DWR的服务 豆。
- 之后,这个远程代理 bean 返回一个 @DataTransferObject POJO 或只是简单的 HTML 字符串
基本上对于 AJAX 应用程序, 第 2 步之后,我希望它转发 到@Controller bean,以便 一切仍在处理中 春天。
I have a web application that integrates DWR 3 and Spring 3. All requests are handled by the Spring's DispatcherServlet. Everything works. When I request an AJAX request, it's handled correctly by the backing DWR service bean annotated with @RemoteProxy. To return a response, my DWR service bean returns either an HTML string including the @DataTransferObject POJO or just the plain POJO.
What I want to do is in the DWR service bean I want it to forward the processing to a Spring @Controller bean. The AJAX request will still be processed by the DWR service but the real processing is delegated to the Spring controller bean. In other words the DWR service bean is just a service facade to the actual service. In this way I'm not duplicating logic.
Is this possible?
Let me clarify further.
In a normal non-AJAX application, when a user submits a form, here's what happens:
- It's forwarded to the
DispatcherServlet - Then to an @Controller annotated bean.
- The processing is then handled by @Service bean.
- Afterwards, the controller returns a ModelAndView.
In a DWR-AJAX application, when a user submits a form, here's what happens:
- It's forwarded to the DispatcherServlet still
- Then to a @RemoteProxy annotated
bean. The processing is handled by
this bean. That's DWR's service
bean. - Afterwards, this remote proxy bean returns either an @DataTransferObject POJO or just plain HTML string
Basically for the AJAX application,
after step 2, I want it to forward
to the @Controller bean so that
everything is still processed by
Spring.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简短的回答是否定的。
DWR 请求中没有 Spring 控制器的位置。 DWR 对远程处理 spring beans 有很大的支持,但是控制器可以为这个等式带来很少的价值。
也就是说,我没有理由认为 Spring 3.0 风格的带注释的控制器不能用作公开的 DWR bean。限制是返回类型不会是 ModelAndView 而是它本身的模型对象。
Short answer is no.
There is no place in a DWR request for a spring controller. DWR has great support for remoting spring beans, but there is little value that a controller could bring to this equation.
That said there is no reason that I can think of that a spring 3.0 style annotated controller couldn't be used as the exposed DWR bean. The restriction would be that the return type would not be
ModelAndView
rather it would just be your model object it's self.我对在这种情况下使用注释不太了解。使用声明性方法,您可以执行以下操作。
在 spring XML 中(注意 fileOperationService 是 spring bean)
你的 bean
你的 DWR.xml
I don't know much about using annotations in this case. With the declarative approach you can do the following.
In spring XML(Note that fileOperationService is the spring bean)
Your bean
Your DWR.xml