json Spring Rest 服务与 Jersey Rest Service 和 Spring+Jersey 解决方案有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26824423/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference among Spring Rest service and Jersey Rest Service and Spring+Jersey solutions?
提问by Terry
I want to build a restful service/API. I used some framework like play to build it but I want to try other more efficient ways. I heard that Jersey is a common library for building the rest API, and Spring is also a good framework. But I also saw some solutions like Spring+Jersey. Thus, I am a little confused about those rest API solutions.
我想构建一个宁静的服务/API。我使用了一些像 play 这样的框架来构建它,但我想尝试其他更有效的方法。听说Jersey是搭建rest API的通用库,Spring也是一个不错的框架。但我也看到了一些解决方案,比如 Spring+Jersey。因此,我对那些 REST API 解决方案感到有些困惑。
Can anyone tell me what is the difference among those ? Jersey REST, Spring Rest and Spring+Jersey Rest ?
谁能告诉我这些有什么区别?Jersey REST、Spring Rest 和 Spring+Jersey Rest ?
My goal is building a couple of rest API that take json as input/output. I have jar file as the backend process logic to process the input json/object and return json/object.
我的目标是构建几个以 json 作为输入/输出的 rest API。我有 jar 文件作为后端处理逻辑来处理输入的 json/object 并返回 json/object。
thanks very much.
非常感谢。
采纳答案by Ross Taylor-Turner
Jersey is the JAX-RS API example implementation provided by Sun, while Spring REST is of course Spring's implementation of the same API/JSRs. The major difference is that Spring REST easily integrates into other Spring APIs (if you wish) such as Spring Data Rest.
Jersey 是 Sun 提供的 JAX-RS API 示例实现,而 Spring REST 当然是 Spring 对相同 API/JSR 的实现。主要区别在于 Spring REST 可以轻松集成到其他 Spring API(如果您愿意),例如Spring Data Rest。
There are a few noteworthy differences between them - you can "embed" Jersey Resources(known in Spring as Controllers) within each other, to enable a separate class that is responsible for the sub-path of a certain path, while this doesn't appear to be available in Spring right now (you have to define the full path). Also, in my opinion Jersey gives better "out of the box" error responses (such as why it can not map a JSON payload to a Java bean using Hymanson) while Spring is a bit more configurable but plainer without some additional work.
它们之间有一些值得注意的区别 - 您可以将 Jersey资源(在 Spring 中称为Controllers)相互“嵌入” ,以启用负责某个路径的子路径的单独类,而这不会似乎现在在 Spring 中可用(您必须定义完整路径)。此外,在我看来,Jersey 提供了更好的“开箱即用”错误响应(例如为什么它无法使用 Hymanson 将 JSON 有效负载映射到 Java bean),而 Spring 的可配置性更强,但更简单,无需一些额外的工作。
In the end the difference in choosing between them usually comes down to - are you already or do you plan to integrate any other Spring libraries into your application? If so Spring REST is the way to go as you'll have a much easier time integrating it, otherwise it is really just personal preference which you'd prefer to use. Personally I like Jersey but the power of other related Spring projects (such as Spring HATEOASwhich I highly recommend) makes Spring the better choice. I don't think there will be a real determining factor in your case.
最后,在它们之间进行选择的区别通常归结为 - 您是否已经或打算将任何其他 Spring 库集成到您的应用程序中?如果是这样,Spring REST 是一种可行的方法,因为您可以更轻松地集成它,否则它实际上只是您更喜欢使用的个人偏好。我个人喜欢 Jersey,但其他相关 Spring 项目(例如我强烈推荐的Spring HATEOAS)的强大功能使 Spring 成为更好的选择。我认为在你的情况下不会有真正的决定因素。
As your "gold" target is a simple API with JSON input/output, I'd recommend you follow the Spring REST guide.
由于您的“黄金”目标是一个带有 JSON 输入/输出的简单 API,我建议您遵循Spring REST 指南。
回答by Wand Maker
One major difference is in the area of unit testing support.
一个主要区别在于单元测试支持领域。
Jersey Test Frameworkdoes not lend itself for mocking server side code - For example, if your REST Resource depended on a Service, you would like to mock the service when testing resource methods. However, Jersey Tests run a separate container and unit tests sort of make calls to the running instance of your REST resource - at this point of time, I have not found any documentation or way for mocking server side code.
Jersey 测试框架不适合模拟服务器端代码 - 例如,如果您的 REST 资源依赖于服务,则您希望在测试资源方法时模拟该服务。但是,Jersey 测试运行一个单独的容器,并且单元测试对 REST 资源的运行实例进行调用——此时,我还没有找到任何文档或模拟服务器端代码的方法。
On the contrary, Spring MVC testsdo not require any containers - and are more well integrated with its controllers. Dependency Injection can be used to inject mock services / DAOs to have better unit tests.
相反,Spring MVC 测试不需要任何容器 - 并且与其控制器更好地集成。依赖注入可用于注入模拟服务/DAO 以进行更好的单元测试。
I also find that documentation on Spring projects are more mature when compared to Jersey.
我还发现与 Jersey 相比,Spring 项目的文档更加成熟。

