![](/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.