【问题标题】:Is a project with Jersey 2.x AND RESTEasy dependencies possible?具有 Jersey 2.x 和 RESTEasy 依赖项的项目是否可行?
【发布时间】:2015-01-27 09:26:43
【问题描述】:

我正在开发一个项目,该项目使用各种客户端应用程序作为 maven 依赖项来与不同的 REST API 通信。

但是在包含使用 Jersey 2.x 实现的客户端和任何其他使用 RESTEasy 的客户端时会出现问题。

一旦我添加了使用 RESTEasy 的依赖项,我就会收到如下错误:

原因:javax.ws.rs.ProcessingException:无法找到 内容类型应用程序/json 和类型类的 MessageBodyReader de.fhg.ipa.vfk.docker.dockerregistry.restclient.entity.SearchResult 在 org.jboss.resteasy.core.interception.ClientReaderInterceptorContext.throwReaderNotFound(ClientReaderInterceptorContext.java:39) 在 org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.getReader(AbstractReaderInterceptorContext.java:73) 在 org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:50) 在 org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(ClientResponse.java:245) 在 org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readEntity(ClientResponse.java:179) 在 org.jboss.resteasy.specimpl.BuiltResponse.readEntity(BuiltResponse.java:211) 在 org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:104) ... 4 更多

或者这个:

原因:javax.ws.rs.ProcessingException:找不到编写器 内容类型应用程序/tar 类型:java.io.FileInputStream at org.jboss.resteasy.core.interception.ClientWriterInterceptorContext.throwWriterNotFoundException(ClientWriterInterceptorContext.java:40) 在 org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.getWriter(AbstractWriterInterceptorContext.java:138) 在 org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:117) 在 org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.writeRequestBody(ClientInvocation.java:341) 在 org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.writeRequestBodyToOutputStream(ApacheHttpClient4Engine.java:558) 在 org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.buildEntity(ApacheHttpClient4Engine.java:524) 在 org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.loadHttpMethod(ApacheHttpClient4Engine.java:423) 在 org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:281) ... 7 更多

是否可以同时使用这两个库或以某种方式配置 maven,以便应用不会尝试使用 RESTEasy 依赖项而不是 Jersey 2.x 依赖项,反之亦然?

谢谢

丹尼尔

【问题讨论】:

    标签: java rest maven jersey resteasy


    【解决方案1】:

    您可以尝试使用 Maven 配置文件来激活 Jersey 或 RESTEasy,但您不能在同一平面类路径中同时拥有两个 JAX-RS 实现。

    如果您必须在一个应用程序中同时使用这两种实现,您将需要由 OSGi 或 JBoss Modules 等模块系统提供的类加载器隔离。

    最好的方法可能是重构您的代码以仅使用 JAX-RS 2.0 客户端 API 并满足于要么 Jersey RESTEasy 用于极端情况需要特定于实现的 API。

    【讨论】:

    • 完全正确的答案。给出解决问题的理由、解决方法和首选方法。我希望在 SO 上看到更多这样的答案。
    • 这个答案在 2021 年仍然正确吗?我知道 Resteasy 切换到 JAX-RS 的 Jakarta 实现,(我认为)与 Jersey 使用的实现相同......这会改变这个答案吗?
    猜你喜欢
    • 2015-03-09
    • 2016-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多