我有一个简单的实体,我试图使用Jersey 2返回。x和杰克逊2。
然而,当我在浏览器中点击端点进行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>
…但既然我在泽西2号x和使用Jackson的提供者(jackson-jaxrs-json-provider
)我不认为这是适合我的方式。
我不知道该怎么做。有人知道我可能错过了什么吗?
谢谢! !
找到问题了…
我忘了加packages("com.fasterxml.jackson.jaxrs.json");
到我的ResourceConfig
班。
现在一切正常!