最近用springboot搭建一个配置系统,使用swagger,但是启动访问页面发现以下问题。
研究发现少了以下配置,这两行很重要:
全部代码如下:
@Configuration
@EnableSwagger2
public class Swagger2 {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.config"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("配置系统API")
.version("1.0")
.description("钟渊-2019-6-15")
.build();
}
}
再次启动正常: