swagger3 关闭配置(快捷方式)
配置参考
springfox:
documentation:
# 总开关(同时设置auto-startup=false,否则/v3/api-docs等接口仍能继续访问)
enabled: false
auto-startup: false
swagger-ui:
enabled: false
配置原理
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
</dependency>
springfox.boot.starter.autoconfigure.OpenApiAutoConfiguration
springfox.boot.starter.autoconfigure.SpringfoxConfigurationProperties
swagger2 关闭配置
swagger2 关闭主要是根据条件使swagger 配置不再生效,如
方法:@ConditionalOnProperty
Configuration
@EnableSwagger2
@ConditionalOnProperty(name = "swagger.enable", havingValue = "true")
public class Swagger2 extends WebMvcConfigurationSupport {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
//为当前包路径
.apis(RequestHandlerSelectors.basePackage("com.yq.demo.controller"))
.paths(PathSelectors.any())
.build();
}
//构建 api文档的详细信息函数,注意这里的注解引用的是哪个
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Spring Boot 测试使用 Swagger2 构建RESTful API")
.contact(new Contact("java乐园", "https://xxx.com", "test@163.com"))
.version("1.0")
.description("User API 描述")
.build();
}
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/swagger-ui.html").addResourceLocations(
"classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations(
"classpath:/META-INF/resources/webjars/");
}
}
application.yml 中配置如下关闭:
swagger:
# 只要不是true就不启用
enable: false
注意:本文归作者所有,未经作者允许,不得转载