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