从哪里开始向 GWT 后端添加 Spring?
我有一个 GWT 应用程序,我想在其中添加 Spring,并且主要使用 Spring 和 JdbcTemplate 来处理我的数据库连接和 DAO 模型。我在 GWT 方面有相当丰富的经验,但我才刚刚开始学习 Spring。
我不清楚在哪里以及如何在 GWT 应用程序中初始化 spring?我需要在我假设的某个地方初始化应用程序上下文。是否可以使用前端的 onModuleLoad() 调用的 RPC 方法来执行此操作,但如果我这样做,对象稍后仍然可用吗?
基本上,我正在寻找有关如何以及在何处初始化后端 Spring 的基本概述,以便我可以开始开发和试验 Springs 组件。
谢谢你!
I have a GWT application in which I would like to add Spring, and mainly use Spring with JdbcTemplate to handle my database connection and DAO model. I am fairly experienced working with GWT but am just starting to learn Spring.
What is not clear to me is where and how I would initialize spring in my GWT application? I need to initialize an application context somewhere I assume. Is it possible to do this with an RPC method invoked from onModuleLoad() in the front-end, but will the objects still be available later on if I do that?
Basically I am looking for a basic overview of how and where to initialize Spring in the back-end so that I can start developing and experimenting with Springs components.
Thank You!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
几年前,我进行了 Spring-GWT 集成,大致步骤如下:
创建一个 RemoteServiceServlet 基类,该类具有从 ServletContext 获取 spring ApplicationContext 的方法。这可以使用如下方法来完成:
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
使所有 RPC servlet 扩展此基类。
这种方法的唯一问题是 RPC servlet 不是由 Spring 创建的,因此您无法注入它们的依赖项。
现在您可以使用第三方框架进行 spring-gwt 集成。例如,GWT Platform 的 Dispatch 模块允许您将操作处理程序配置为 spring bean。此类解决方案基本上采用框架提供的单个 RPC servlet。该框架 RPC servlet 负责实例化服务器端处理程序并调用它们。如果您愿意学习这些附加框架,它们可能是比我上面概述的更好的长期解决方案。
Several years ago, I did a Spring-GWT integration with roughly the following steps:
Create a base RemoteServiceServlet class that have methods for acquiring spring ApplicationContext from ServletContext. This can be done using something like following:
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
Make all the RPC servlets extends this base class.
The only problem with this approach was that the RPC servlet are not them-self not created by Spring so you cannot have their dependencies injected.
Now you can employ third-party frameworks for spring-gwt integration. For example GWT Platform's Dispatch module lets you configure your action handler's as spring beans. Such solutions basically employ a single RPC servlet provided by the framework. This framework RPC servlet is responsible for instantiating your server-side handlers and invoking them. If you are willing to learn these additional frameworks, they might be better long-term solutions than the one I outlined above.