2017-05-21 31 views
0

我添加了Swagger到我的Dropwizard服務,而且它工作的很好。Dropwizard Jersey設置URL模式打破Swagger 404?

但是現在,我想添加一個簡單的HTML頁面,並配置從 /assets服務內容,它打破招搖和API 與 404反應

這是我的代碼資源路徑

public class NumericodeApplication extends Application<NumericodeConfiguration> { 

    public static void main(final String[] args) throws Exception { 
     new NumericodeApplication().run(args); 
    } 

    @Override 
    public String getName() { 
     return "Numericode"; 
    } 

    @Override 
    public void initialize(final Bootstrap<NumericodeConfiguration> bootstrap) { 

     bootstrap.addBundle(new SwaggerBundle<NumericodeConfiguration>() { 
      @Override 
      protected SwaggerBundleConfiguration getSwaggerBundleConfiguration(NumericodeConfiguration configuration) { 
       return configuration.swaggerBundleConfiguration; 
      } 
     }); 

     bootstrap.addBundle(new AssetsBundle("/assets", "/", "index.html")); //added this 
    } 

    @Override 
    public void run(final NumericodeConfiguration configuration, final Environment environment) { 

     environment.jersey().register(new Controller()); 
     environment.jersey().setUrlPattern("/swagger"); //tried this 
     environment.jersey().setUrlPattern("/api/*"); //added this 
    } 
} 

當我嘗試刪除兩個setUrlPattern()方法調用它抱怨

多個servlet地圖路徑/ *:資產[映射:JAVAX_API:空],io.dropwizard.jersey.setup.JerseyServletContainer-2e5b7fba [映射:嵌入式:空]

但是,如果我刪除的資產包揚鞭OK再次工作?

我怎樣才能讓我的索引頁和Swagger在Dropwizard/Jetty上工作。

獎勵積分,如果你能解釋發生了什麼!

回答

1

您的應用程序或靜態資產可以通過 根路徑提供,但不能同時提供。當使用Dropwizard返回一個Javascript應用程序時,後者是很有用的 。要啓用它,請將您的應用程序移動到 的子URL。

來源:http://www.dropwizard.io/1.1.0/docs/manual/core.html#serving-assets

bootstrap.addBundle(new AssetsBundle("/assets", "/", "index.html"));

該行正試圖在root上下文路徑安裝在assets資源目錄中的資源。可能澤西島的應用程序已經安裝在那裏。