我正在开发一个项目,该项目使用各种客户端应用程序作为 Maven 依赖项来与不同的 REST API 通信。
但是,当包含一个使用 Jersey 2.x 实现的客户端和任何其他使用 RESTEasy 的客户端时,就会出现问题。
一旦我添加了使用 RESTEasy 的依赖项,我就会得到这样的错误:
Caused by: javax.ws.rs.ProcessingException: Unable to find a MessageBodyReader of content-type application/json and type class de.fhg.ipa.vfk.docker.dockerregistry.restclient.entity.SearchResult at org.jboss.resteasy.core.interception.ClientReaderInterceptorContext.throwReaderNotFound(ClientReaderInterceptorContext.java:39) at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.getReader(AbstractReaderInterceptorContext.java:73) at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:50) at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(ClientResponse.java:245) at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readEntity(ClientResponse.java:179) at org.jboss.resteasy.specimpl.BuiltResponse.readEntity(BuiltResponse.java:211) at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:104) ... 4 more
或者这个:
Caused by: javax.ws.rs.ProcessingException: could not find writer for content-type application/tar type: java.io.FileInputStream at org.jboss.resteasy.core.interception.ClientWriterInterceptorContext.throwWriterNotFoundException(ClientWriterInterceptorContext.java:40) at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.getWriter(AbstractWriterInterceptorContext.java:138) at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:117) at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.writeRequestBody(ClientInvocation.java:341) at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.writeRequestBodyToOutputStream(ApacheHttpClient4Engine.java:558) at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.buildEntity(ApacheHttpClient4Engine.java:524) at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.loadHttpMethod(ApacheHttpClient4Engine.java:423) at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:281) ... 7 more
是否可以同时使用这两个库或以某种方式配置 maven,以便应用程序不会尝试使用 RESTEasy 依赖项而不是 Jersey 2.x 依赖项,反之亦然?
谢谢
丹尼尔
最佳答案
您可以尝试使用 Maven 配置文件来激活 Jersey 或 RESTEasy,但您不能在同一平面类路径中同时拥有两个 JAX-RS 实现。
如果您必须在一个应用程序中同时使用这两种实现,则需要由 OSGi 或 JBoss 模块等模块系统提供的类加载器隔离。
最好的方法可能是重构您的代码以仅使用 JAX-RS 2.0 客户端 API,并满足于 Jersey 或 RESTEasy 以解决极端情况需要特定于实现的 API。
关于java - 具有 Jersey 2.x 和 RESTEasy 依赖项的项目是否可行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28167002/