![](/img/trans.png)
[英]GET request to a RESTful resource results in MessageBodyWriter not found
[英]Jersey throwing “MessageBodyWriter not found” exception on every GET request?
我有一个简单的实体,尝试使用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
),所以我认为这不是我的理想选择。
我不确定如何进行此操作。.有人对我可能缺少的内容有任何想法吗?
谢谢!!
好,找到问题了...
我忘了加
packages("com.fasterxml.jackson.jaxrs.json");
到我的ResourceConfig
类。
现在一切正常!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.