SpringBoot線上環(huán)境徹底關(guān)閉Swagger-UI的方式
概要
Springboot線上環(huán)境徹底關(guān)閉Swagger-UI
整體架構(gòu)流程
1.SwaggerConfig使用@Profile排除線上環(huán)境其他環(huán)境生效
2.創(chuàng)建一個(gè)控制類使用@Profile僅線上環(huán)境生效,使訪問swagger-ui.html返回404
技術(shù)細(xì)節(jié)
/** * @author: suitman * @description: go fucking comment.... * @create: 2021-02-07 10:43 **/ @Configuration @EnableSwagger2 @Profile("!prod") public class SwaggerConfig implements WebMvcConfigurer { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(new ApiInfoBuilder() // 設(shè)置標(biāo)題 .title("****") // 描述 .description("***") // 作者信息 .contact(new Contact("***", null, null)) // 版本 .version("版本號(hào): 1") .build()) .select() .apis(RequestHandlerSelectors.withClassAnnotation(Api.class)) .paths(PathSelectors.any()) .build(); } @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/"); registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); } }
import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Profile; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @Profile("prod") @RestController @Slf4j public class DisableSwaggerUiController { @RequestMapping(value = "swagger-ui.html", method = RequestMethod.GET) public void getSwagger(HttpServletResponse httpResponse) throws IOException { httpResponse.setStatus(HttpStatus.NOT_FOUND.value()); } }
小結(jié)
通過這種方式可以徹底關(guān)閉線上環(huán)境訪問swagger-ui.html直接返回404
到此這篇關(guān)于SpringBoot線上環(huán)境徹底關(guān)閉Swagger-UI的方式的文章就介紹到這了,更多相關(guān)SpringBoot徹底關(guān)閉Swagger-UI內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
詳解springboot+mybatis多數(shù)據(jù)源最簡解決方案
本篇文章主要介紹了詳解springboot+mybatis多數(shù)據(jù)源最簡解決方案,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05Springboot GET和POST請(qǐng)求參數(shù)獲取方式小結(jié)
Spring Boot GET和POST請(qǐng)求參數(shù)獲取是開發(fā)人員經(jīng)常需要解決的問題,本文主要介紹了Springboot GET和POST請(qǐng)求參數(shù)獲取方式小結(jié),具有一定的參考價(jià)值,感興趣的可以了解一下2023-09-09使用Java解析JSON數(shù)據(jù)并提取特定字段的實(shí)現(xiàn)步驟(以提取mailNo為例)
在現(xiàn)代軟件開發(fā)中,處理JSON數(shù)據(jù)是一項(xiàng)非常常見的任務(wù),無論是從API接口獲取數(shù)據(jù),還是將數(shù)據(jù)存儲(chǔ)為JSON格式,解析和提取JSON中的特定字段都是開發(fā)人員需要掌握的基本技能,本文將以一個(gè)實(shí)際案例為例,詳細(xì)介紹如何使用Java解析JSON數(shù)據(jù)并提取其中的mailNo字段2025-01-01Java中EasyPoi多sheet導(dǎo)出功能實(shí)現(xiàn)
這篇文章主要介紹了Java中EasyPoi多sheet導(dǎo)出功能實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01Java中Spring技巧之?dāng)U展點(diǎn)的應(yīng)用
這篇文章主要介紹了Java中Spring技巧之?dāng)U展點(diǎn)的應(yīng)用,下文Spring容器的啟動(dòng)流程圖展開其內(nèi)容的相關(guān)資料,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-04-04Java實(shí)戰(zhàn)之仿天貓商城系統(tǒng)的實(shí)現(xiàn)
這篇文章主要介紹了如何利用Java制作一個(gè)基于SSM框架的迷你天貓商城系統(tǒng),文中采用的技術(shù)有JSP、Springboot、SpringMVC、Spring等,需要的可以參考一下2022-03-03