JAX-RS in relation to Jersey and JSRs(JAX-RS 与 Jersey 和 JSR 相关)
问题描述
我正在尝试理解 Java 中的一些概念:
I'm trying to get my head around some concepts in Java:
- JSR(s):描述规范,但没有实际的实现.例如.http://jsr311.java.net/ 是Java™ API for RESTful Web Services"的家"".它是所有 JSR-311 实现的通用参考.
- 可以从 http://下载 JSR-311 的接口 (?)/mvnrepository.com/artifact/javax.ws.rs/jsr311-api,但是,除非您自己实现 JSR-311,否则这些没有特别的价值?
- JSR(s) 通常/总是有一个参考实现.要找到它,您必须搜索JSR XXX 参考实现"或查看规范主页(例如 http://jsr311.java.net/)
- 对于 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 技术?)
- 把两个 http://mvnrepository.com/artifact/javax.ws.rs/jsr311-api 和 http://mvnrepository.com/artifact/com.sun.jersey/jersey-server/1.9 因为项目中的依赖项可能会导致类路径问题?
- 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.
- 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?
- 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/)
- 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?)
- 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?
推荐答案
是的,这不是什么新鲜事.想想 JDBC,java 提供了接口(
Connection
、Statement
、ResultSet
等),但它已启动向数据库供应商提供实施.
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 相关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:JAX-RS 与 Jersey 和 JSR 相关
基础教程推荐
- 降序排序:Java Map 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01