国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Springboot線(xiàn)上環(huán)境徹底關(guān)閉Swagger-UI

這篇具有很好參考價(jià)值的文章主要介紹了Springboot線(xiàn)上環(huán)境徹底關(guān)閉Swagger-UI。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

概要

Springboot線(xiàn)上環(huán)境徹底關(guān)閉Swagger-UI

整體架構(gòu)流程

1.SwaggerConfig使用@Profile排除線(xiàn)上環(huán)境其他環(huán)境生效
2.創(chuàng)建一個(gè)控制類(lèi)使用@Profile僅線(xiàn)上環(huán)境生效,使訪(fǎng)問(wè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ò)這種方式可以徹底關(guān)閉線(xiàn)上環(huán)境訪(fǎng)問(wèn)swagger-ui.html直接返回404文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-578601.html

到了這里,關(guān)于Springboot線(xiàn)上環(huán)境徹底關(guān)閉Swagger-UI的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶(hù)投稿,該文觀(guān)點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • Springboot整合Swagger2后訪(fǎng)問(wèn)swagger-ui.html 404報(bào)錯(cuò)

    Springboot整合Swagger2后訪(fǎng)問(wèn)swagger-ui.html 404報(bào)錯(cuò)

    在spring boot項(xiàng)目中配置Swagger2,配置好了但是訪(fǎng)問(wèn)確實(shí)404,SwaggerConfig中的注入方法也執(zhí)行了還是訪(fǎng)問(wèn)不到頁(yè)面。究其原因是MVC沒(méi)有找到swagger-ui包中的swagger-ui.html文件和css樣式、js等文件。 解決?案: ?案1. 降低Swagger2的使用版本 ?案2. 使?配置?下+swagger-ui.html+指定的css?錄

    2024年02月11日
    瀏覽(27)
  • swagger 3.0.0 集成 springboot 2.6+ 生成doc.html 和swagger-ui

    swagger 3.0.0 集成 springboot 2.6+ 生成doc.html 和swagger-ui

    1.項(xiàng)目中引入pom.xml依賴(lài) 特別說(shuō)明: doc.html模式 swagger-bootstrap-ui只支持Swagger 2 knife4j是swagger-bootstrap-ui的升級(jí)版,支持Swagger 3。 2.創(chuàng)建Swagger2Config配置類(lèi) 3.啟動(dòng)類(lèi)輸出文檔地址 項(xiàng)目運(yùn)行后 控制臺(tái)輸出log見(jiàn)下圖 點(diǎn)擊任意文檔鏈接都可以進(jìn)入對(duì)應(yīng)的文檔

    2024年02月12日
    瀏覽(25)
  • SpringBoot整合Swagger踩坑-項(xiàng)目啟動(dòng)報(bào)錯(cuò)與swagger-ui.html請(qǐng)求404無(wú)法訪(fǎng)問(wèn)

    SpringBoot整合Swagger踩坑-項(xiàng)目啟動(dòng)報(bào)錯(cuò)與swagger-ui.html請(qǐng)求404無(wú)法訪(fǎng)問(wèn)

    依賴(lài) 常見(jiàn)依賴(lài)接入方式如下: springfox推薦 依賴(lài)接入方式如下: 建議使用推薦的方式,可以協(xié)助我們解決404異常的問(wèn)題。 配置 依賴(lài)導(dǎo)入完成后創(chuàng)建 SwaggerConfig.java 配置: 報(bào)錯(cuò)信息: org.springframework.context.ApplicationContextException: Failed to start bean ‘documentationPluginsBootstrapper’; n

    2024年02月01日
    瀏覽(33)
  • Springboot配置Swagger展示API文檔并進(jìn)行接口測(cè)試(doc.html、swagger-ui.html)

    Springboot配置Swagger展示API文檔并進(jìn)行接口測(cè)試(doc.html、swagger-ui.html)

    三、創(chuàng)建一個(gè)測(cè)試接口 http://localhost:8080/doc.html http://localhost:8080/swagger-ui.html

    2024年02月10日
    瀏覽(17)
  • springboot2.7以上版本配置swagger3.0.0版本瀏覽器無(wú)法打開(kāi)swagger-ui

    1.最實(shí)用解決方式:將pom里的swagger依賴(lài)降到2.9.0即可 過(guò)低無(wú)法啟動(dòng)項(xiàng)目 1.2 Springboot2.6以后將SpringMVC 默認(rèn)路徑匹配策略從AntPathMatcher 更改為PathPatternParser Springfox 使用的路徑匹配是基于A(yíng)ntPathMatcher的,而Spring Boot 2.6.X使用的是PathPatternMatcher 2.3.0.0版本swagger2訪(fǎng)問(wèn)地址為:http://loca

    2024年02月11日
    瀏覽(21)
  • 【SpringDoc】SpringBoot 3 swagger-ui.html 報(bào)404 SpringDoc 官方文檔問(wèn)題(可能)

    本文針對(duì) SpringBoot 3.x 版本??! SpringDoc v2 官方文檔:https://springdoc.org/v2/ 舊版本的 swagger 和 1.x 版本的SpringDoc 均不支持 SpringBoot 3,所以對(duì)于 SpringBoot3 如下的兩種 Swagger 或 SpringDoc 依賴(lài) 均不可用 ,注意,是 不可用 無(wú)數(shù)的文章甚至 官方文檔 都表示,swagger-ui 界面的網(wǎng)址是 htt

    2024年02月16日
    瀏覽(27)
  • Springboot 實(shí)踐(2)MyEclipse2019創(chuàng)建項(xiàng)目修改pom文件,加載springboot 及swagger-ui jar包

    Springboot 實(shí)踐(2)MyEclipse2019創(chuàng)建項(xiàng)目修改pom文件,加載springboot 及swagger-ui jar包

    MyEclipse2019創(chuàng)建工程之后,需要添加Springboot啟動(dòng)函數(shù)、添加application.yml配置文件、修改pom文件添加項(xiàng)目使用的jar包。 添加Springboot啟動(dòng)函數(shù) 創(chuàng)建文件存儲(chǔ)路徑 (1)右鍵單擊“src/main/java”文件夾,彈出對(duì)話(huà)框輸入路徑名稱(chēng)“com.SJL.action.app”,點(diǎn)擊“finish”按鈕,完成路徑創(chuàng)建。

    2024年02月12日
    瀏覽(18)
  • swagger-ui

    swagger-ui

    目錄 一、swagger-ui簡(jiǎn)介 1.1 swagger-ui原理 1.2 swagger-ui特點(diǎn) 二、swagger-ui+springboot頁(yè)面使用 2.1 swagger-ui的依賴(lài) 2.2?加入以上依賴(lài)要注意的點(diǎn) 2.3 工具類(lèi) 3.4 swagger-ui 常用注解 @Api (修飾類(lèi)) @ApiOperation(修飾方法) @ApiParam (接收參數(shù)) @ApiModel (修飾參數(shù)對(duì)象類(lèi)) @ApiModelProperty(修飾參數(shù)對(duì)象

    2024年02月02日
    瀏覽(22)
  • 接口工具Swagger2和Swagger-UI的使用

    接口工具Swagger2和Swagger-UI的使用

    目錄 一、為什么需要接口可視化工具? 二、Swagger-UI介紹: 1、在項(xiàng)目的pom文件中導(dǎo)入swagger2的依賴(lài) 2、下載Swagger-UI項(xiàng)目 3、引入Swagger-UI 4、編寫(xiě)配置文件 第一種: 第二種: 5、訪(fǎng)問(wèn)api文檔頁(yè)面 6、如果訪(fǎng)問(wèn)失敗,則進(jìn)行第六步,如果訪(fǎng)問(wèn)成功,就不用操作了。 我們的項(xiàng)目通常

    2024年02月08日
    瀏覽(31)
  • java 整合 swagger-ui 步驟

    java 整合 swagger-ui 步驟

    1.在xml 中添加Swagger 相關(guān)依賴(lài) 2.配置Swagger 3.啟動(dòng)項(xiàng)目,訪(fǎng)問(wèn) Swagger UI 訪(fǎng)問(wèn)地址:http://localhost:xxx/swagger-ui.html出現(xiàn)下面界面則配置成功 4.更改界面風(fēng)格 4.1 添加依賴(lài) 4.2 啟動(dòng)項(xiàng)目,并訪(fǎng)問(wèn) 訪(fǎng)問(wèn)地址:http://localhost:xxxx/doc.html 4.3效果 5.Swagger 注解 6.遇見(jiàn)的問(wèn)題

    2024年02月09日
    瀏覽(27)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包