[英]org/glassfish/jersey/jackson/JacksonFeature is not defined in my rest API
我創建了一個小的 REST API,它似乎工作得很好。 我想使用 Twitter API 並顯示一些推文。 但是當我嘗試這樣做時,我的服務器會引發錯誤。
嘗試此 URL 時,訪問我的舊資源之一效果很好: http://localhost:8080/api-mashup-api/api/v1/foo/bar :
@GET
@Path("/bar")
@Produces(MediaType.TEXT_HTML)
public String print2() {
return "This should be printed if in foo/bar";
}
但是,如果我在http://localhost:8080/api-mashup-api/api/v1/foo/twitter嘗試我的“推特方法”:
@GET
@Path("/twitter")
@Produces(MediaType.TEXT_HTML)
public String print5() {
//I have my real tokens here of course.
ClientIdentifier ci = new ClientIdentifier("clientID",
"ClientSecret");
OAuth2CodeGrantFlow flow = OAuth2ClientSupport
.authorizationCodeGrantFlowBuilder(ci,
"https://api.twitter.com/oauth2/token", "https://api.twitter.com/oauth2/token")
.scope("contact")
.build();
String finalAuthorizationUri = flow.start();
return "This is the bearer: " + finalAuthorizationUri.toString();
}
它引發以下錯誤:
HTTP Status 500 - org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: org/glassfish/jersey/jackson/JacksonFeature
實際上,它應該只打印我的不記名令牌。 我曾嘗試導入各種 jackson jar 文件,但未能使其正常工作。 我可能會補充說我使用 Tomcat v8 而不是 Glassfish 服務器。
您缺少一個 jar,特別是 jersey-media-json-jackson-2.XX.jar(其中 XX 是您使用的球衣版本)
您可以添加 Maven 依賴項,例如:
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.media/jersey-media-json-jackson -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.26</version>
</dependency>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.