泽西版本问题:找不到媒体类型 = 应用程序/xml 的 MessageBodyReader [英] Jersey version issue: MessageBodyReader not found for media type=application/xml

查看:24
本文介绍了泽西版本问题:找不到媒体类型 = 应用程序/xml 的 MessageBodyReader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编写一个使用 XML 数据的简单 Jersey 客户端时,我遇到了这个异常MessageBodyReader not found for media type=application/xml".我的所有设置,包括 jersey-client 作为 maven 依赖项都很好.我使用的版本是 2.17.一旦我将版本降级到 2.15,它就开始正常工作了.谁能解释需要包含哪些依赖项才能使 2.17 版正常工作.

While writing a simple Jersey client that was consuming XML data, I came across this exception "MessageBodyReader not found for media type=application/xml". All of my settings, including the jersey-client as maven dependencies was just fine. The version that I was using was 2.17. Once I degraded the version to 2.15 it started working fine. Can anyone explain what dependencies that needs to be included for version 2.17 to work.

Maven 依赖(适用于 2.15 及更低版本)

Maven Dependency (works on 2.15 and lower)

<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-client</artifactId>
    <version>${jersey.version}</version>
</dependency>

使用服务的 Java 代码片段

Java Code Snippet for consuming the service

Client c = ClientBuilder.newClient();
WebTarget target = null;
target = c.target(Main.BASE_URI_XML);

String customerId = "415D7AB5";

XYZ response = target.path(customerId).request(MediaType.APPLICATION_XML).get(XYZ.class);

推荐答案

看看 27.3.从 Jersey 2.15 迁移到 2.16

27.3.1.1.与核心分离的 JAX-B 提供程序

从 2.16 版开始,所有 JAX-B 提供程序都捆绑在一个单独的模块中.

From version 2.16 onwards, all JAX-B providers are being bundled in a separate module.

<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-jaxb</artifactId>
    <version>2.17</version>
</dependency>

这篇关于泽西版本问题:找不到媒体类型 = 应用程序/xml 的 MessageBodyReader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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