2017-05-04 47 views
0

我对球衣2和灰熊(无web.xml)中设置招摇。我可以访问swagger页面,但是我的API资源没有出现。 Swagger page i'm referring to is seen below没有上市出现使用上招摇球衣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> 

回答

1

看过谷歌表格后,事实证明,独立版本的招摇并不实际工作。

我创建了一个单独的Maven web应用程序,并加入我的球衣项目作为依赖。这在摆脱了与我使用的球衣版本相匹配的大摇大摆的版本之后工作。