Java Spring MVC REST 不符合 JAX-RS。有关系吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20007164/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 22:17:02  来源:igfitidea点击:

Spring MVC REST is not JAX-RS compliant. Does it matter?

javaspringrestspring-mvcjax-rs

提问by user6123723

I've had good experience with Spring MVC REST with a couple of solid projects delivered. My question is about JAX-RS compliance. Does it matter because Spring is here to stay and I don't foresee (nor have a reason to) having to move away from Spring MVC REST to Jersy or any other JAX-RS impl any time soon. Anything that should force me to think about using JAX-RS implementation as opposed to Spring MVC REST?

我在 Spring MVC REST 方面有很好的经验,并交付了几个可靠的项目。我的问题是关于 JAX-RS 合规性。这是否重要,因为 Spring 将继续存在,我不认为(也没有理由)很快就必须从 Spring MVC REST 迁移到 Jersy 或任何其他 JAX-RS impl。有什么应该迫使我考虑使用 JAX-RS 实现而不是 Spring MVC REST?

采纳答案by Takahiko Kawasaki

IMHO, if your web application returns JSON/XML only, there is no big difference. However, if some end points of your web application need to return HTML, Spring MVC is better. The reason I think so is that JAX-RS does not provide any MVC mechanism (AFAIK). Jersey (one of JAX-RS implementations) provides Viewable/Template to support MVC, but it is a Jersey-specific feature and not a part of JAX-RS specification.

恕我直言,如果您的 Web 应用程序仅返回 JSON/XML,则没有太大区别。但是,如果您的 Web 应用程序的某些端点需要返回 HTML,则 Spring MVC 会更好。我这么认为的原因是 JAX-RS 不提供任何 MVC 机制(AFAIK)。Jersey(JAX-RS 实现之一)提供 Viewable/Template 来支持 MVC,但它是 Jersey 特定的功能,而不是 JAX-RS 规范的一部分。

Chapter 18. MVC Templates
https://jersey.java.net/documentation/latest/mvc.html

第 18 章 MVC 模板
https://jersey.java.net/documentation/latest/mvc.html

Also, this blog may give you some insights.

此外,这个博客可能会给你一些见解。

Jersey JAX-RS MVC Killed the Spring MVC Star
http://sleeplessinslc.blogspot.jp/2012/02/jersey-jax-rs-mvc-killed-spring-mvc.html
(The conclusion of the blog is different from its title, though.)

Jersey JAX-RS MVC 杀死了 Spring MVC 之星
http://sleeplessinslc.blogspot.jp/2012/02/jersey-jax-rs-mvc-killed-spring-mvc.html
(博客的结论与其标题不同, 尽管。)



EDIT - here's the answer to the question asked:

编辑 - 这是所问问题的答案:

Standardized annotations

标准化注解

As the 2nd link above says:

正如上面的第二个链接所说:

Jersey is a JAX-RS implementation, one could swap out Jersey for another provider like RestEasy if desired without much effort. Spring MVC on the other hand has REST web service support but the same is not a JAX-RS implementation and therefore one is tied to Spring MVC.

Jersey 是一个 JAX-RS 实现,如果需要,可以将 Jersey 替换为另一个提供程序,如 RestEasy,无需太多努力。另一方面,Spring MVC 具有 REST Web 服务支持,但它不是 JAX-RS 实现,因此它与 Spring MVC 相关联。