繁体   English   中英

org/glassfish/jersey/jackson/JacksonFeature 未在我的 rest API 中定义

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM