[英]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.