简体   繁体   English

Jersey在每个GET请求上引发“找不到MessageBodyWriter”异常?

[英]Jersey throwing “MessageBodyWriter not found” exception on every GET request?

I have a simple entity that I'm attempting to return using Jersey 2.x and Jackson 2.x for JSON encoding. 我有一个简单的实体,尝试使用Jersey 2.x和Jackson 2.x返回以进行JSON编码。

However when I hit the endpoint in the browser for a GET request, it fails with: 但是,当我在浏览器中向端点请求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.

I suspect this is due to some lacking dependency or versions not matching. 我怀疑这是由于某些缺乏依赖性或版本不匹配所致。 I tried several but still I get the same issue. 我尝试了几次,但仍然遇到相同的问题。

I'm using Maven, and here is how the jersey-related dependencies look like: 我正在使用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>

I read some folks fixing this by adding the follow dependency: 我读了一些通过添加以下依赖项来解决此问题的人:

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

...but since I'm on Jersey 2.x and using Jackson's provider ( jackson-jaxrs-json-provider ) I don't think that is the way to go for me. ...但是由于我使用的是Jersey 2.x,并且使用Jackson的提供程序( jackson-jaxrs-json-provider ),所以我认为这不是我的理想选择。

I'm not sure how to proceed here.. anyone has any ideas on what could I be missing? 我不确定如何进行此操作。.有人对我可能缺少的内容有任何想法吗?

Thank you!! 谢谢!!

Ok, found the issue... 好,找到问题了...

I forgot to add 我忘了加

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

to my ResourceConfig class. 到我的ResourceConfig类。

Now everything is working! 现在一切正常!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 对RESTful资源的GET请求导致找不到MessageBodyWriter - GET request to a RESTful resource results in MessageBodyWriter not found 泽西2.11和ResourceMethodInvocationHandlerProvider:未找到MessageBodyWriter - Jersey 2.11 and ResourceMethodInvocationHandlerProvider : MessageBodyWriter not found 嵌入式Jetty的Jersey-找不到MessageBodyWriter application / json - Jersey with embedded Jetty - MessageBodyWriter not found application/json 找不到媒体类型的 Jersey MessageBodyWriter=text/plain - Jersey MessageBodyWriter not found for media type=text/plain 泽西岛-XmlRootElement /实体的返回列表-找不到MessageBodyWriter - Jersey - return list of XmlRootElement/Entities - MessageBodyWriter not found 找不到multipart / mixed MessageBodyWriter(Jersey,Servicemix) - multipart/mixed MessageBodyWriter not found (Jersey, Servicemix) 其余的JAX-RS异常,找不到MessageBodyWriter - Rest JAX-RS exception, MessageBodyWriter not found 使用Jersey发送多个文件:找不到multipart / form-data的MessageBodyWriter - Sending multiple files with Jersey: MessageBodyWriter not found for multipart/form-data 泽西与Grizzly:找不到媒体类型= application / json的MessageBodyWriter - Jersey with Grizzly: Getting MessageBodyWriter not found for media type=application/json 泽西(Jersey)REST错误,找不到媒体类型= application / json的MessageBodyWriter - Jersey REST error, MessageBodyWriter not found for media type=application/json
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM