与Jersey和JSR相关的JAX-RS [英] JAX-RS in relation to Jersey and JSRs

查看:193
本文介绍了与Jersey和JSR相关的JAX-RS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图了解Java中的一些概念:

I'm trying to get my head around some concepts in Java:


  1. JSR(s):描述规范,但不带实际实施。例如。 http://jsr311.java.net/ 是用于RESTful Web服务的Java™API的主页 。它是JSR-311所有实现的通用参考。

  2. 可以从 http://mvnrepository.com/artifact/javax.ws.rs/jsr311-api ,但是,除非您正在实施JSR -311你自己没有特别的价值?

  3. JSR(s)通常/总是有一个参考实现。要找到它,您必须谷歌JSR XXX参考实施或查看规格主页(例如 http:// jsr311 .java.net /

  4. 对于JSR-311,这个参考实现是泽西。使用maven,您可以从 http://mvnrepository.com/获取球衣服务器神器/ com.sun.jersey /球衣服务器/ 1.9 。由于
    Jersey根据 http://中提供的接口提供实现mvnrepository.com/artifact/javax.ws.rs/jsr311-api ,您只需要在项目中添加Jersey作为依赖项,而不是jsr311-api本身。 (这适用于所有JSR技术?)

  5. 同时放置 http://mvnrepository.com/artifact/javax.ws.rs/jsr311-api http://mvnrepository.com/artifact/com.sun.jersey/jersey-server/1.9 作为项目中的依赖项可能会导致类路径问题吗?

  1. JSR(s): describe specifications, but carry no actual implementations. E.g. http://jsr311.java.net/ is the "home" for "Java™ API for RESTful Web Services". It serves as a common reference for all implementations of JSR-311.
  2. One can download the interfaces (?) of JSR-311 from http://mvnrepository.com/artifact/javax.ws.rs/jsr311-api, however, unless you are implementing JSR-311 by yourself these have no particular value?
  3. JSR(s) will usually/always have a reference implementation. To find it you'll have to google "JSR XXX reference implementation" or see the specifications home page (e.g. http://jsr311.java.net/)
  4. For JSR-311 this reference implementation is Jersey. Using maven you can get the jersey server from http://mvnrepository.com/artifact/com.sun.jersey/jersey-server/1.9. Since Jersey provides an implementation according to the interfaces found in http://mvnrepository.com/artifact/javax.ws.rs/jsr311-api, you only need to add Jersey as a dependency in your project and not the jsr311-api itself. (this applies to all JSR technologies?)
  5. Putting both http://mvnrepository.com/artifact/javax.ws.rs/jsr311-api and http://mvnrepository.com/artifact/com.sun.jersey/jersey-server/1.9 as dependencies in your project will possibly cause classpath problems?

我是完全关闭还是某些人?

Am I completely off or onto someting?

推荐答案


  1. 是的,这不是什么新鲜事。想想JDBC,java提供
    接口(连接语句 ResultSet 等)但数据库供应商提供实现的价格上涨了

  1. Yes, this isn't anything new. Think about JDBC, java provides the interfaces (Connection, Statement, ResultSet etc) but it is up to database vendors to provide implementations.

如果您使用的是JSR- 311实现如Jersey或Apache CXF
然后您将使用 javax.ws.rs 注释注释您的类,例如 @Path @GET @Produces 等。这就是你需要显式拥有JSR的原因-311作为maven依赖。

If you're using a JSR-311 implementation like Jersey or Apache CXF then you'll annotate your classes with the javax.ws.rs annotations, such as @Path, @GET, @Produces etc. This is why you need to explicitly have JSR-311 as a maven dependency.

是的,通常。请查看维基上的 JSR列表

Yes, usually. Have a look at the JSR list on wiki.

您需要JSR和实现。注释在JSR中,实现提供支持类,例如 com.sun.jersey.spi.container.servlet.ServletContainer

You need both the JSR and the implementation. The annotations are in the JSR, the implementation provides supporting classes, such as com.sun.jersey.spi.container.servlet.ServletContainer.

不,有必要兼顾两者(见第4点);你不会遇到类路径冲突。

No, it is necessary to have both as dependencies (see point 4); you won't get classpath conflicts.

这篇关于与Jersey和JSR相关的JAX-RS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆