2017-02-20 108 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