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

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

问题描述

我正在尝试理解 Java 中的一些概念:

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

  1. JSR(s):描述规范,但没有实际的实现.例如.http://jsr311.java.net/ 是Java™ API for RESTful Web Services"的家"".它是所有 JSR-311 实现的通用参考.
  2. 可以从 http://下载 JSR-311 的接口 (?)/mvnrepository.com/artifact/javax.ws.rs/jsr311-api,但是,除非您自己实现 JSR-311,否则这些没有特别的价值?
  3. JSR(s) 通常/总是有一个参考实现.要找到它,您必须搜索JSR XXX 参考实现"或查看规范主页(例如 http://jsr311.java.net/)
  4. 对于 JSR-311,此参考实现是 Jersey.使用 maven,您可以从 http://mvnrepository.com/获取球衣服务器工件/com.sun.jersey/jersey-server/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-apihttp://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 提供了接口(ConnectionStatementResultSet 等),但它已启动向数据库供应商提供实施.

  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.

是的,通常.查看 wiki 上的 JSR 列表.

你需要 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.

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

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