生产环境需要关闭swaggerui
- 启动判断写到配置文件中,根据条件判断是否加载
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Value("${swagger.show}")
private boolean swaggerShow;
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.enable(swaggerShow)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("org.xx.controller"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("RESTful APIs")
.description("用于项目前端接口调用")
.termsOfServiceUrl("")
.contact("")
.version("1.0")
.termsOfServiceUrl("11")
.build();
}
}
- 资源文件是否扫描
@Configuration
@ComponentScan(value = "org.xx.interceptor")
class WebMvcConfig extends WebMvcConfigurerAdapter {
@Value("${swagger.show}")
private boolean swaggerShow;
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
if (this.swaggerShow) {
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
}
- 配置文件中
swagger.show=true
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014087707/article/details/79347153