2015-10-14 33 views
0

我有一個澤西應用程序在內置的Grizzly中運行,並且鉤住Swagger。 Swagger在我從Eclipse運行應用程序時工作正常。 http://localhost:8080/myapp/api-docs返回預期JSON響應Swagger打包成超級罐子後不工作

{ 
"apiVersion": "1.0.0", 
"swaggerVersion": "1.2", 
"apis": [ 
    { 
     "path": "/myresource", 
     "description": "Hello my resource description" 
    } 
]} 

然而,將應用程序打包成一個單一的罐子和運行所得到的罐後的URL,揚鞭停止工作。訪問相同的URL http://localhost:8080/myapp/api-docs現在返回HTTP狀態500.應用程序本身工作正常 - 我可以向Web服務發起請求。

這是我用來打包應用程序的pom.xml

<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/maven-v4_0_0.xsd"> 

    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.example</groupId> 
    <artifactId>simple-service</artifactId> 
    <packaging>jar</packaging> 
    <version>1.0-SNAPSHOT</version> 
    <name>simple-service</name> 

    <dependencyManagement> 
     <dependencies> 
      <dependency> 
       <groupId>org.glassfish.jersey</groupId> 
       <artifactId>jersey-bom</artifactId> 
       <version>${jersey.version}</version> 
       <type>pom</type> 
       <scope>import</scope> 
      </dependency> 
     </dependencies> 
    </dependencyManagement> 

    <dependencies> 
     <dependency> 
      <groupId>org.glassfish.jersey.containers</groupId> 
      <artifactId>jersey-container-grizzly2-http</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.glassfish.jersey.media</groupId> 
      <artifactId>jersey-media-moxy</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>com.wordnik</groupId> 
      <artifactId>swagger-jersey2-jaxrs_2.10</artifactId> 
      <version>1.3.12</version> 
     </dependency> 
     <dependency> 
      <groupId>ch.qos.logback</groupId> 
      <artifactId>logback-classic</artifactId> 
      <version>1.0.1</version> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.9</version> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>2.5.1</version> 
       <inherited>true</inherited> 
       <configuration> 
        <source>1.7</source> 
        <target>1.7</target> 
       </configuration> 
      </plugin> 

      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-shade-plugin</artifactId> 
       <version>1.6</version> 
       <configuration> 
        <createDependencyReducedPom>true</createDependencyReducedPom> 
        <filters> 
         <filter> 
          <artifact>*:*</artifact> 
          <excludes> 
           <exclude>META-INF/*.SF</exclude> 
           <exclude>META-INF/*.DSA</exclude> 
           <exclude>META-INF/*.RSA</exclude> 
          </excludes> 
         </filter> 
        </filters> 
       </configuration> 

       <executions> 
        <execution> 
         <phase>package</phase> 
         <goals> 
          <goal>shade</goal> 
         </goals> 
         <configuration> 
          <transformers> 
           <transformer 
            implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" /> 
           <transformer 
            implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
            <manifestEntries> 
             <Main-Class>com.example.Main</Main-Class> 
            </manifestEntries> 
           </transformer> 
          </transformers> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 

      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>exec-maven-plugin</artifactId> 
       <version>1.2.1</version> 
       <executions> 
        <execution> 
         <goals> 
          <goal>java</goal> 
         </goals> 
        </execution> 
       </executions> 
       <configuration> 
        <mainClass>com.example.Main</mainClass> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 

    <properties> 
     <jersey.version>2.22.1</jersey.version> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 
</project> 
+0

你能找到日誌來確定500錯誤實際上是什麼嗎? –

+0

不幸的是,日誌文件中沒有任何內容。看起來api-docs /路徑無法訪問,這就是爲什麼它返回500. 如果它有用,我使用的堆棧:Grizzly,Jersey,Maven - 全部打包到一個可執行的jar文件中。 – His

回答

1

您使用的swagger的版本非常陳舊,並且包含對scala的依賴關係等等。建議升級到1.5.3,它具有較小的依賴列表。

最有可能您的jar文件具有不兼容的傑克遜版本導致此問題。

與下降嚮導Swagger建立一個沒有問題的優步罐。