【发布时间】:2018-05-24 08:59:11
【问题描述】:
当我尝试将 Swagger 集成到一个非常简单的 Spring Boot REST 应用程序中时,Swagger-UI.html 不会显示和获取我自定义的 API 信息。我应该如何更改以下代码,以便 Swagger UI 页面显示自定义的 API 信息?我也无法调试 SwaggerConfig 类,将断点放入,但是当作为 Spring Boot 应用程序运行时,断点不会停止。
我在 pom.xml 中有什么:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
我的 SwaggerConfig 类:
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket messageApi() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("cool-report-api")
.apiInfo(apiInfo())
.select()
.paths(messageApiPaths()).build();
}
private Predicate<String> messageApiPaths() {
return or(regex("/api/topics.*"), regex("/api/message.*"));
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Cool Message Receiver API")
.description("Cool Message Receiver REST API Reference")
.termsOfServiceUrl("http://www.cool-message-receiver.com")
.contact(new Contact("John Smith", null, "john.smith@cool.com"))
.license("Cool Proprietary Software")
.licenseUrl("www.cool-message.com")
.version("0.1.0")
.build();
}
}
但是在我 spring-boot:run 上面的代码之后,自定义的 API Info 似乎不起作用,Swagger 仍然显示默认的“Api Documentation”标题和“Apache 2.0”许可证等。这是我看到的现在:
【问题讨论】:
标签: spring maven spring-boot swagger-ui swagger-2.0