【发布时间】:2017-02-20 21:52:02
【问题描述】:
我想将 Swagger 2.0 与我的 Spring Boot RESTful Web 服务一起使用来生成文档。我已经搜索了相当多的答案。基本上我有一个带有一组控制器的 Spring Boot 项目,我想记录 API。我的 POM 文件中有以下依赖项设置。
<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 的Swagger 配置类:
@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-docs 或 http://localhost:8080/myapp/api-docs 之类的 URL 上看到某些内容,我假设“myapp”上述 URL 的一部分是指我的主要所在的类的名称(这是否正确)?此外,我已经尝试使用端口 8080 和端口 80 进行此操作,最重要的是,除了无法访问站点外,我什么也看不到。我查看了here 和here 提供的答案,但是我没有任何成功。任何帮助将不胜感激,在此先感谢您。
【问题讨论】: