2017-02-20 107 views
0

我想使用Swagger 2.0和Spring Boot RESTful web服務來生成文檔。我已經搜索了相當多的答案。基本上我有一個控制器的Spring Boot項目,我想記錄API的。我在我的POM文件中設置了以下依賴項。Swagger Spring Boot的REST API文檔

<dependency> 
     <groupId>io.springfox</groupId> 
     <artifactId>springfox-swagger-ui</artifactId> 
     <version>2.4.0</version> 
    </dependency> 
    <dependency> 
     <groupId>io.springfox</groupId> 
     <artifactId>springfox-swagger2</artifactId> 
     <version>2.5.0</version> 
    </dependency> 

這是我揚鞭配置類與@Configuration和@ EnableSwagger2:

 @Configuration 
     @EnableSwagger2 
public class SwaggerConfig { 

    @Bean 
    public Docket api(){ 
     return new Docket(DocumentationType.SWAGGER_2) 
      .select() 
      .apis(RequestHandlerSelectors.any()) 
      .paths(PathSelectors.regex("/api/.*")) 
      .build() 
      .apiInfo(apiInfo()); 
    } 

    private ApiInfo apiInfo() { 
     return new ApiInfoBuilder() 
      .title("My application title") 
      .description("This is a test of documenting EST API's") 
      .version("V1.2") 
      .termsOfServiceUrl("http://terms-of-services.url") 
      .license("LICENSE") 
      .licenseUrl("http://url-to-license.com") 
      .build(); 
    } 

} 

從我所聚集在閱讀了幾個其他的答案在這裏,在這一點上,我應該能夠看到一些網址,如http://myapp/v2/api-docshttp://localhost:8080/myapp/api-docs我做了一個假設,上面的URL的「myapp」部分引用了我的主要駐留的類的名稱(這是否正確)?我也嘗試過使用端口8080和端口80,而底線是我看不到其他網站無法訪問的東西。我已經看過提供的答案herehere但是我沒有取得任何成功。任何幫助將不勝感激,先謝謝你。

+0

試試這個:HTTP://本地主機: 8080/myapp/swagger-ui.html –

回答

0

正如你可以在下面的文檔,請參見: https://springfox.github.io/springfox/docs/snapshot/#springfox-swagger-ui

端點現在是招搖,ui.html,對於你的情況,這將是http://localhost:8080/myapp/swagger-ui.html

+0

謝謝,另外一個問題,URL的「myapp」部分是我的「main」所在類的名稱? – TKPhillyBurb

+0

我在看netstat時甚至沒有看到使用端口8080。 – TKPhillyBurb

+0

http://stackoverflow.com/questions/24452072/how-do-i-choose-the-url-for-my-spring-boot-webapp – fbak