【问题标题】:Jersey throwing "MessageBodyWriter not found" exception on every GET request?Jersey 在每个 GET 请求上都抛出“找不到 MessageBodyWriter”异常?
【发布时间】:2014-06-26 22:37:26
【问题描述】:

我有一个简单的实体,我正尝试使用 Jersey 2.x 和 Jackson 2.x 进行 JSON 编码。

但是,当我在浏览器中点击 GET 请求的端点时,它失败了:

HTTP Status 500 - org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=application/json, type=class com.package.ResponseWrapper, genericType=class com.package.ResponseWrapper.

我怀疑这是由于某些缺少依赖项或版本不匹配造成的。我尝试了几个,但仍然遇到同样的问题。

我正在使用 Maven,以下是与球衣相关的依赖项的样子:

    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet</artifactId>
        <version>2.9.1</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-server</artifactId>
        <version>2.9.1</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-common</artifactId>
        <version>2.9.1</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.ext</groupId>
        <artifactId>jersey-entity-filtering</artifactId>
        <version>2.9.1</version>
    </dependency>

    <dependency> 
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.4.1</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.jaxrs</groupId>
        <artifactId>jackson-jaxrs-json-provider</artifactId>
        <version>2.4.1</version>
    </dependency>

我读到一些人通过添加以下依赖项来解决此问题:

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-json</artifactId>
    <version>1.8</version>
</dependency>

...但是由于我在 Jersey 2.x 上并使用 Jackson 的提供程序 (jackson-jaxrs-json-provider),我认为这不是我要走的路。

我不确定如何在此处继续.. 有人对我可能缺少什么有任何想法吗?

谢谢!!

【问题讨论】:

    标签: java json jackson jax-rs jersey-2.0


    【解决方案1】:

    好的,找到问题了……

    忘记加了

    packages("com.fasterxml.jackson.jaxrs.json");
    

    致我的ResourceConfig 班级。

    现在一切正常!

    【讨论】:

      猜你喜欢
      • 2021-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多