Java REST 实现:Jersey 与 CXF

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

Java REST implementation: Jersey vs CXF

javaweb-servicesrestcxfjersey

提问by dexter

What do you think is the advantages/disadvantages between this two libraries? Which of these two are best suited for production environment? By the way I will be using JSON instead of XML.

您认为这两个库之间的优缺点是什么?这两个中哪一个最适合生产环境?顺便说一下,我将使用 JSON 而不是 XML。

I also would like to know what library is most supported by the community e.g. tutorials, documentation.

我还想知道社区最支持哪个库,例如教程、文档。

回答by Jan Algermissen

I have only used Jersey (with great satisfaction) so I cannot give a real comparison. Things you might want to consider:

我只使用过泽西岛(非常满意),所以我无法进行真正的比较。您可能需要考虑的事项:

  • CXF is packaged up with SOAP stack support so you bring in a lot of SOAP-related weight you'll never use when you build a RESTful system. (There are plans to split the packaging as far as I know, though)
  • Jersey comes with a number of non-standard additions to JAX-RS that are very helpful. There is also a client side core framework which is designed quite nicely.
  • [Warning: Shameless plug ahead (sorry)]: I have been working on an extended Jersey client side framework that encourages proper use of REST on the client side and is (IMHO at least) very natural to use. It is planned to announce it this (or next) week - if you care about the client side a lot, give it a try. Personally, I'd consider that a huge pro-Jersey argument.
  • CXF 与 SOAP 堆栈支持打包在一起,因此您引入了许多与 SOAP 相关的权重,这些权重在您构建 RESTful 系统时永远不会使用。(不过,据我所知,有计划拆分包装)
  • Jersey 为 JAX-RS 提供了许多非常有用的非标准补充。还有一个客户端核心框架,设计得非常好。
  • [警告:无耻的插件(抱歉)]:我一直在开发一个扩展的 Jersey 客户端框架,该框架鼓励在客户端正确使用 REST,并且(至少恕我直言)使用起来非常自然。计划在本周(或下周)宣布 - 如果您非常关心客户端,请尝试一下。就个人而言,我认为这是一个巨大的支持泽西岛的论点。

HTH,

哈,

Jan

回答by Nick Klauer

I have used both, but for different purposes. CXF worked great to parse a WSDL and create Java POJOs to interact with, so CXF is pretty good for client-side WSDL services. I'm currently using Jersey for server-side implementation and I am impressed with the simplicity of getting up-and-running with RESTful services using Jersey.

我两个都用过,但目的不同。CXF 非常适合解析 WSDL 并创建 Java POJO 以进行交互,因此 CXF 非常适合客户端 WSDL 服务。我目前正在使用 Jersey 进行服务器端实现,我对使用 Jersey 启动和运行 RESTful 服务的简单性印象深刻。

As Jersey is mainly devoted to RESTful services and CXF deals mostly (all?) with SOAP, I think it comes down to whether you want to work with SOAP or REST, and determine the best framework for the job from there. Personally, I am more in the REST camp than SOAP, but my needs are different. Should I be in a situation where the vendor/customer/company I write the service for needs some sort of contract, I might still push for REST (and REST's equivalent for contract-based services, WADL), but would likely be required to implement a SOAP service, in which case I would look at CXF first and everything else second.

由于 Jersey 主要致力于 RESTful 服务,而 CXF 主要(全部?)与 SOAP 打交道,我认为这归结为您想使用 SOAP 还是 REST,并从那里确定最适合这项工作的框架。就个人而言,与 SOAP 相比,我更倾向于 REST 阵营,但我的需求不同。如果我的供应商/客户/公司需要某种合同来编写服务,我可能仍然会推动 REST(以及 REST 与基于合同的服务的等价物,WADL),但可能需要实施SOAP 服务,在这种情况下,我会首先查看 CXF,然后再查看其他所有内容。

Personally, Jersey is pretty good for a JAX-RS framework, although don't exclude RESTEasy, by JBoss. I like both, but the documentation for RESTEasy is better.

就个人而言,Jersey 非常适合 JAX-RS 框架,尽管不排除JBoss 的RESTEasy。两者我都喜欢,但 RESTEasy 的文档更好。

For CXF, the documentation is OK, but I ran into inconsistencies in how I needed to handle SSL and HTTP Proxies, but it worked itself out eventually. CXF does provide more out of the box regarding these additional features, and I would say RESTEasy would provide the equivalent functionality for RESTful frameworks.

对于 CXF,文档还可以,但是我在处理 SSL 和 HTTP 代理的方式方面遇到了不一致的问题,但最终还是解决了。CXF 确实提供了更多关于这些附加功能的开箱即用的功能,我想说 RESTEasy 将为 RESTful 框架提供等效的功能。

回答by dafmetal

Did you consider RESTlet? It is a powerful package to quickly build RESTful web services. The people behind RESTlet also write the RESTlet In Action book which is currently in early access. The chapters that are already available do a very good job of explaining REST and detailing how you go about designing a REST api.

你考虑过RESTlet吗?它是一个强大的包,可以快速构建 RESTful Web 服务。RESTlet 背后的人还编写了 RESTlet In Action 一书,该书目前处于抢先体验阶段。已有的章节很好地解释了 REST 并详细说明了如何设计 REST api。

回答by Blair

I've used Apache CXF for JAX-WS and Jersey for JAX-RS so I can't comment about CXF and REST. It was easy to set up a REST example using Jersey. The documentation was adequate. I haven't used RESTEasy but Jersey looks to have more traction and more recent updates.

我已经将 Apache CXF 用于 JAX-WS,将 Jersey 用于 JAX-RS,因此我无法评论 CXF 和 REST。使用 Jersey 设置 REST 示例很容易。文件是足够的。我没有使用过 RESTEasy,但 Jersey 看起来有更多的吸引力和更新的更新。

A good book for implementation guidelines is RESTful Web Services Cookbook.

一本关于实现指南的好书是 RESTful Web Services Cookbook。

回答by David J. Liszewski

If you are concerned about the details of converting a solution developed with Jerseyto run on CXF, Glen Mazza posted a collection of Jersey samples ported to Apache CXF on GitHub. The README files have notes for each sample regarding necessary changes made.

如果您担心将使用Jersey开发的解决方案转换为在CXF上运行的详细信息,Glen Mazza 在 GitHub 上发布了一组移植到 Apache CXF 的 Jersey 示例。README 文件对每个示例都有关于所做的必要更改的注释。