0
我對球衣2和灰熊(無web.xml)中設置招搖。我可以訪問swagger頁面,但是我的API資源沒有出現。 沒有上市出現使用上招搖球衣2灰熊
我的主要文件被視爲低於
`
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得到球衣-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>