From 91103a119f84bef47549f8adbfaf736b034dd373 Mon Sep 17 00:00:00 2001 From: bai <1643359946@qq.com> Date: Wed, 26 Jun 2024 23:04:03 +0800 Subject: [PATCH] =?UTF-8?q?2024=E5=B9=B46=E6=9C=8826=E6=97=A5=20=E5=85=B3?= =?UTF-8?q?=E9=97=ADswagger=EF=BC=8C=E7=A6=81=E6=AD=A2=E8=AE=BF=E9=97=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jeecg/config/WebMvcConfiguration.java | 16 +++++++++++++++- .../src/main/resources/application-test.yml | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java b/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java index d0ba9c95..0e28edc3 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java @@ -20,6 +20,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; +import org.springframework.http.HttpStatus; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.cors.CorsConfiguration; @@ -51,6 +52,13 @@ public class WebMvcConfiguration implements WebMvcConfigurer { @Value("${spring.resource.static-locations:}") private String staticLocations; + @Value("${knife4j.production}") + private boolean knife4jIsProduction; + + + + + @Autowired(required = false) private PrometheusMeterRegistry prometheusMeterRegistry; @@ -73,7 +81,13 @@ public class WebMvcConfiguration implements WebMvcConfigurer { */ @Override public void addViewControllers(ViewControllerRegistry registry) { - registry.addViewController("/").setViewName("doc.html"); + //如果开启了swagger直接跳过去,如果没开,直接让它404 + if(!knife4jIsProduction){ + registry.addViewController("/").setViewName("doc.html"); + } else { + registry.addViewController("/").setStatusCode(HttpStatus.NOT_FOUND); + registry.addViewController("/doc.html").setStatusCode(HttpStatus.NOT_FOUND); + } } @Bean diff --git a/jeecg-module-system/jeecg-system-start/src/main/resources/application-test.yml b/jeecg-module-system/jeecg-system-start/src/main/resources/application-test.yml index 1a4bff94..2ecb181c 100644 --- a/jeecg-module-system/jeecg-system-start/src/main/resources/application-test.yml +++ b/jeecg-module-system/jeecg-system-start/src/main/resources/application-test.yml @@ -250,7 +250,7 @@ knife4j: #开启增强配置 enable: true #开启生产环境屏蔽 - production: false + production: true basic: enable: true username: jeecg