JAX-RS 2.0 更改默认实现 [英] JAX-RS 2.0 change default implementation
问题描述
我正在尝试使用 RESTEasy 作为 JAX-RS 2.0 客户端实现.问题是我遇到了运行时异常:
I'm trying to use RESTEasy as JAX-RS 2.0 client implementation. The problem is that I got runtime exception:
06-28 13:29:06.410: E/AndroidRuntime(5745): Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder
06-28 13:29:06.410: E/AndroidRuntime(5745): at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:103)
所以 newBuilder()
方法正在搜索 JerseyClientBuilder
如果我理解正确的话.如何让系统改用 RESTEasy?
So the newBuilder()
method is searching for JerseyClientBuilder
if I understand it correct. How can I tell the system to use RESTEasy instead?
推荐答案
嗯,JAX-RS 依赖于 Service Provider 约定.在 newBuilder
方法的第一行,您可以阅读:
Well, JAX-RS relies on the Service Provider convention.
On the first lines of the newBuilder
method you can read:
Object delegate = FactoryFinder.find(JAXRS_DEFAULT_CLIENT_BUILDER_PROPERTY,
JAXRS_DEFAULT_CLIENT_BUILDER);
其中 JAXRS_DEFAULT_CLIENT_BUILDER_PROPERTY
是 "javax.ws.rs.client.ClientBuilder"
反过来,FactoryFinder
看起来
- 先将类名改成
META-INF/services/javax.ws.rs.client.ClientBuilder
- 然后在
javax.ws.rs.client.ClientBuilder
属性中放入${java.home}/lib/jaxrs.properties
- 最后进入System属性
javax.ws.rs.client.ClientBuilder
.
- first for the class name into
META-INF/services/javax.ws.rs.client.ClientBuilder
- then in the property
javax.ws.rs.client.ClientBuilder
into${java.home}/lib/jaxrs.properties
- finally into the System property
javax.ws.rs.client.ClientBuilder
.
所以,要使用 RESTEasy,你应该创建一个文件
So, to use RESTEasy, you should create a file
META-INF/services/javax.ws.rs.client.ClientBuilder
附上文字:
org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder
这是RESTEasy的类名ClientBuilder
which is the class name of the RESTEasy ClientBuilder
这篇关于JAX-RS 2.0 更改默认实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!