需要在 Struts2 和 Spring 中实现 RESTful Web 服务
我目前正在开发一个基于 Strtus2、Spring、open JPA 和 LDAP 的 Web 应用程序.
I am currently working on a web application that is based on Strtus2, Spring, open JPA and LDAP.
现在客户希望我们为这个系统开发 RESTful api,以便其他网站或应用程序可以与它集成.
Now client wants us to develop RESTful api for this system so that other websites or application can integrate with it.
这项任务已分配给我,我显然不知道从哪里开始.
This task has been assigned to me and I clearly have no idea from where to start.
我做了研究发现,有一个插件 struts2-rest
并且对于 Spring 有几种不同的方法.
I have done my research and found out that, there is a plugin struts2-rest
and for Spring there are several different ways.
除此之外,我看到的大多数示例都使用 Maven,但我们的项目没有使用它.
More to that most of the example I have been seen are using Maven, but our project does not use that.
所以,我只需要一个方向来开始这件事.
So, I just need a direction to start this thing.
推荐答案
在 Struts2 中你可以通过 struts2-rest-plugin 实现 RESTful api.起点是 REST 插件.
In Struts2 you can implement RESTful api via struts2-rest-plugin. The starting point is REST Plugin.
假设你有一个普通的 Struts 2 应用程序,你需要做的就是这个 REST 演示是添加以下两个插件:
Setting Up
Assuming you have a normal Struts 2 application, all you need to do for this REST demo is to add the following two plugins:
Struts 2 Rest Plugin
Struts 2 Convention Plugin
注意,您可以从 Maven Central 下载这些插件的 jars配置(struts.xml)
Note, you can download the jars for these plugins from Maven Central Configuration ( struts.xml )
只是将插件放入您的应用程序可能不会产生正是想要的效果.有几个考虑因素.这首先要考虑的是您是否想要任何非 RESTful URL与您的 RESTful URL 共存.我们将展示两种配置.这首先假设您想要做的就是 REST.第二个假设你想要在同一个 Struts 2 中保持其他非 RESTful URL 的活动应用.
Just dropping the plugin's into your application may not produce exactly the desired effect. There are a couple of considerations. The first consideration is whether you want to have any non-RESTful URL's coexisting with your RESTful URL's. We'll show two configurations. The first assumes all you want to do is REST. The second assumes you want to keep other non-RESTful URL's alive in the same Struts 2 application.
在 Home 的 Struts2 文档中,您将找到开始开发 Struts2 应用程序所需的一切.
In the Home of Struts2 docs you'll find everything necessary to start developing Struts2 application.
- Struts 2 Rest Showcase Webapp
- 创建 java web 应用程序使用 AngularJS 和 Struts2
- Struts 2 + REST Web 服务集成示例
相关文章