簡體   English   中英

球衣2上使用swagger並沒有出現列表

[英]no listing appears using swagger on jersey 2 with grizzly

我已經在jersey 2和灰熊(沒有web.xml)上設置了招搖。 我可以訪問頁面,但是我的API資源沒有出現。 我所指的揮舞頁面如下所示

我的主文件如下所示

`    
package com.beraben.jersey.test;

import com.wordnik.swagger.jaxrs.config.BeanConfig;
import java.net.URI;
import org.glassfish.grizzly.http.server.CLStaticHttpHandler;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
import org.glassfish.jersey.server.ResourceConfig;

/**
 *
 * @author Evan
 */
public class jerseyTestMain {

    /**
     * @param args the command line arguments
     */
    public static final String BASE_URI = "http://localhost:8080/myapp/";

    public static HttpServer startServer() {
        // create a resource config that scans for JAX-RS resources and providers
        // in com.example.rest package
        final ResourceConfig rc = new ResourceConfig().packages("com.beraben.jersey.test", "com.wordnik.swagger.jersey.listing");

        BeanConfig config = new BeanConfig();
        config.setResourcePackage("com.beraben.jersey.test");
        config.setVersion("1.0.0");
        config.setScan(true);

        // create and start a new instance of grizzly http server
        // exposing the Jersey application at BASE_URI
        return GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
    }

    public static void main(String[] args) throws InterruptedException {
        final HttpServer server = startServer();

        CLStaticHttpHandler staticHttpHandler = new CLStaticHttpHandler(jerseyTestMain.class.getClassLoader(), "swagger-ui/");
        server.getServerConfiguration().addHttpHandler(staticHttpHandler, "/docs");

        Object syncObj = new Object();
        synchronized (syncObj) {
            syncObj.wait();
        }

    }

}    
`

我也在下面看到了API設置

   package com.beraben.jersey.test;

import com.wordnik.swagger.annotations.Api;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

/**
 *
 * @author Evan
 */
@Path("myresource")
@Api(value = "/myresource")
public class MyResource {
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String getIt(){
        return "Got it!";
    }
}

我使用API​​沒問題,它可以正確返回。

但是由於某種原因,我不能大張旗鼓地顯示有關API調用的詳細信息,我是否需要做更多的事情才能使它顯示有關代碼中現有API的詳細信息?

我的靜態文件是從樣本項目jersey2-grizzly2-swagger-demo復制的

另外,作為參考,這是我的pom文件(與演示項目沒有太大區別是我不使用dependencyManagment來獲取jersey-bom,而是直接引用它)。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.beraben</groupId>
    <artifactId>jersey-test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <dependencies>
        <dependency>
            <groupId>org.glassfish.jersey.archetypes</groupId>
            <artifactId>jersey-quickstart-grizzly2</artifactId>
            <version>2.22.2</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey</groupId>
            <artifactId>jersey-bom</artifactId>
            <version>2.22.2</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-grizzly2-http</artifactId>
            <version>2.22.2</version>
        </dependency>
        <dependency>
            <groupId>com.wordnik</groupId>
            <artifactId>swagger-jersey-jaxrs_2.10</artifactId>
            <version>1.3.13</version>
        </dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
</project>

在查看完Google表單后,事實證明獨立版本的swagger實際上不起作用。

我創建了一個單獨的Maven Web應用程序,並將我的jersey項目添加為依賴項。 在擺弄與我使用的球衣版本相匹配的搖搖晃晃的版本之后,此方法就起作用了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM