2024年6月26日 关闭swagger,禁止访问

This commit is contained in:
bai 2024-06-26 23:04:03 +08:00
parent 1cf148a66c
commit 91103a119f
2 changed files with 16 additions and 2 deletions

View File

@ -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

View File

@ -250,7 +250,7 @@ knife4j:
#开启增强配置
enable: true
#开启生产环境屏蔽
production: false
production: true
basic:
enable: true
username: jeecg