Java spring mvc 和 Jersey 的区别

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

Difference between spring mvc and Jersey

javarestspring-mvcjersey

提问by Muthu

Is there any trade off between using Spring mvc and Jersey Rest servlet container ? Jersey follows Jax RS standard. When I learn Spring mvc, more or less looks the same. In some applications I found people use jersey spring servlet. If spring (dispatcher servlet with handler mapping) can do all the work, then what is the need of Jersey here ? Thanks in advance.

使用 Spring mvc 和 Jersey Rest servlet 容器之间是否有任何权衡?Jersey 遵循 Jax RS 标准。当我学习 Spring mvc 时,或多或少看起来是一样的。在一些应用程序中,我发现人们使用 jersey spring servlet。如果 spring(带有处理程序映射的调度程序 servlet)可以完成所有工作,那么这里需要 Jersey 吗?提前致谢。

回答by chrylis -cautiouslyoptimistic-

Spring MVC is a full Web frontend framework including support for HTML and other templating, plus other features, in addition to the JSON/XML REST features provided by Jersey.

除了 Jersey 提供的 JSON/XML REST 功能之外,Spring MVC 是一个完整的 Web 前端框架,包括对 HTML 和其他模板的支持,以及其他功能。

Spring MVC was around first and has its own way of doing things. JAX-RS was defined as a standard for annotation-based REST handlers, and Jersey is an implementation of that standard. (It's very similar to @Autowiredand CDI.)

Spring MVC 最早出现并且有自己的做事方式。JAX-RS 被定义为基于注释的 REST 处理程序的标准,而 Jersey 是该标准的实现。(它@Autowired与 CDI非常相似。)

I personally prefer Spring MVC because I build on a Spring stack and can reuse code between my JSON and HTML handlers, but components intended to be deployed as one part of a customer's own system might be more flexible if using JAX-RS.

我个人更喜欢 Spring MVC,因为我构建在 Spring 堆栈上并且可以在我的 JSON 和 HTML 处理程序之间重用代码,但是如果使用 JAX-RS,打算作为客户自己系统的一部分部署的组件可能会更灵活。

回答by Paul Samsotha

Personally I think it's just a matter of preference and what perspective you are looking at it from. I would go on to say that when making this consideration, when building different tiers, you can say that there is an extra "REST layer", on top of the other business, persistence, etc. layers. Just like persistence implementations can be swapped out, so can REST implementations.

我个人认为这只是一个偏好问题,以及你从什么角度看待它。我会继续说,在考虑这一点时,在构建不同的层时,您可以说在其他业务、持久性等层之上还有一个额外的“REST 层”。就像持久性实现可以交换一样,REST 实现也可以。

That being said, though the endpoint/controller/resource classes look similar in implementation, other features (of the REST layer) are implemented completely different. Looking at it from a Spring perspective, I think those comfortable with Spring would choose to keep MVC as the REST implementation, for it's familiarity

话虽如此,虽然端点/控制器/资源类在实现上看起来很相似,但其他功能(REST 层)的实现完全不同。从 Spring 的角度来看,我认为那些对 Spring 感到满意的人会选择将 MVC 作为 REST 实现,因为它很熟悉

Looking at it from a Jersey perspective, this is where I think most of the integration decision comes in; choosing how to implement the layers below the REST layer. For that Spring would be a viable choice, as it has a rich eco system. But being a Jersey user, the Jersey framework (for a REST implementation) seems a lot more intuitive, but that is completely bias. To use Spring and Jersey together, you can have a look at Combining Spring project and Jersey

从泽西岛的角度来看,这是我认为大部分整合决策的地方;选择如何实现 REST 层下面的层。对于那个 Spring 将是一个可行的选择,因为它拥有丰富的生态系统。但是作为 Jersey 用户,Jersey 框架(用于 REST 实现)似乎更直观,但这完全是偏见。要将 Spring 和 Jersey 一起使用,您可以查看Combining Spring project and Jersey

As far as Jersey being a JAX-RS implementation, I don't see it being a deciding factor in choosing the REST implementation, when looking at it from a Spring perspective. I really don't see it being much of a factor at all. In a Java EE environment, sure you can swap out implementations with little hassle, but when Spring integration is involved, it's not that easy, as there are integration modules and configurations involved in integrating each different JAX-RS implementations with Spring.

就 Jersey 作为 JAX-RS 实现而言,从 Spring 的角度来看,我认为它不是选择 REST 实现的决定性因素。我真的不认为这是一个很大的因素。在 Java EE 环境中,确保您可以毫不费力地更换实现,但是当涉及 Spring 集成时,就没有那么容易了,因为在将每个不同的 JAX-RS 实现与 Spring 集成时涉及到集成模块和配置。