2024年6月27日 关闭swagger
This commit is contained in:
parent
91103a119f
commit
5e1182c405
|
@ -5,10 +5,13 @@ import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.jeecg.common.constant.CommonConstant;
|
import org.jeecg.common.constant.CommonConstant;
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.context.annotation.Profile;
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
|
@ -42,8 +45,13 @@ import java.util.stream.Collectors;
|
||||||
@EnableSwagger2 //开启 Swagger2
|
@EnableSwagger2 //开启 Swagger2
|
||||||
@EnableKnife4j //开启 knife4j,可以不写
|
@EnableKnife4j //开启 knife4j,可以不写
|
||||||
@Import(BeanValidatorPluginsConfiguration.class)
|
@Import(BeanValidatorPluginsConfiguration.class)
|
||||||
|
//@Profile({"dev", "local"})
|
||||||
|
//@ConditionalOnProperty(name = "swagger.enable", havingValue = "true")
|
||||||
public class Swagger2Config implements WebMvcConfigurer {
|
public class Swagger2Config implements WebMvcConfigurer {
|
||||||
|
|
||||||
|
@Value("${knife4j.production:false}")
|
||||||
|
private boolean knife4jIsProduction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* 显示swagger-ui.html文档展示页,还必须注入swagger资源:
|
* 显示swagger-ui.html文档展示页,还必须注入swagger资源:
|
||||||
|
@ -52,10 +60,12 @@ public class Swagger2Config implements WebMvcConfigurer {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||||
|
if(!knife4jIsProduction){
|
||||||
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
|
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
|
||||||
registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
|
registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
|
||||||
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* swagger2的配置文件,这里可以配置swagger2的一些基本的内容,比如扫描的包等等
|
* swagger2的配置文件,这里可以配置swagger2的一些基本的内容,比如扫描的包等等
|
||||||
|
@ -65,6 +75,7 @@ public class Swagger2Config implements WebMvcConfigurer {
|
||||||
@Bean(value = "defaultApi2")
|
@Bean(value = "defaultApi2")
|
||||||
public Docket defaultApi2() {
|
public Docket defaultApi2() {
|
||||||
return new Docket(DocumentationType.SWAGGER_2)
|
return new Docket(DocumentationType.SWAGGER_2)
|
||||||
|
.enable(!knife4jIsProduction)
|
||||||
.apiInfo(apiInfo())
|
.apiInfo(apiInfo())
|
||||||
.select()
|
.select()
|
||||||
//此包路径下的类,才生成接口文档
|
//此包路径下的类,才生成接口文档
|
||||||
|
|
|
@ -52,13 +52,9 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
|
||||||
@Value("${spring.resource.static-locations:}")
|
@Value("${spring.resource.static-locations:}")
|
||||||
private String staticLocations;
|
private String staticLocations;
|
||||||
|
|
||||||
@Value("${knife4j.production}")
|
@Value("${knife4j.production:false}")
|
||||||
private boolean knife4jIsProduction;
|
private boolean knife4jIsProduction;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Autowired(required = false)
|
@Autowired(required = false)
|
||||||
private PrometheusMeterRegistry prometheusMeterRegistry;
|
private PrometheusMeterRegistry prometheusMeterRegistry;
|
||||||
|
|
||||||
|
@ -85,8 +81,8 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
|
||||||
if(!knife4jIsProduction){
|
if(!knife4jIsProduction){
|
||||||
registry.addViewController("/").setViewName("doc.html");
|
registry.addViewController("/").setViewName("doc.html");
|
||||||
} else {
|
} else {
|
||||||
registry.addViewController("/").setStatusCode(HttpStatus.NOT_FOUND);
|
registry.addViewController("/").setViewName("404");
|
||||||
registry.addViewController("/doc.html").setStatusCode(HttpStatus.NOT_FOUND);
|
registry.addViewController("/doc.html").setViewName("404");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -246,6 +246,13 @@ logging:
|
||||||
level:
|
level:
|
||||||
org.jeecg.modules.system.mapper: info
|
org.jeecg.modules.system.mapper: info
|
||||||
#swagger
|
#swagger
|
||||||
|
springfox:
|
||||||
|
documentation:
|
||||||
|
# 总开关(同时设置auto-startup=false,否则/v3/api-docs等接口仍能继续访问)
|
||||||
|
enabled: false
|
||||||
|
auto-startup: false
|
||||||
|
swagger-ui:
|
||||||
|
enabled: false
|
||||||
knife4j:
|
knife4j:
|
||||||
#开启增强配置
|
#开启增强配置
|
||||||
enable: true
|
enable: true
|
||||||
|
|
Loading…
Reference in New Issue