首页 文章

没有列表出现使用swigger在球衣2与灰熊

提问于
浏览
0

我在jersey 2和grizzly(没有web.xml)上设置了swagger . 我可以访问swagger页面但是我的API资源没有出现 .
Swagger page i'm referring to is seen below

我的主要文件如下所示

`    
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>

1 回答

  • 1

    在查看谷歌表格之后,事实证明,swagger的独立版本实际上并不起作用 .

    我创建了一个单独的maven web应用程序,并将我的泽西项目添加为依赖项 . 这是在摆弄了与我正在使用的球衣版本相匹配的昂首阔步版本之后 .

相关问题