springboot-2.3.3.RELEASE升級2.7.16,swagger2.9.2升級3.0.0過程

一、pom文件版本修改

<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.16</version><relativePath/>
</parent>

如果用到了“spring-boot-starter-web”,“spring-boot-starter-validation”,“spring-boot-devtools”,“spring-boot-starter-test”,“spring-boot-test”。。。這些依賴也統一配置為2.7.X。

二、升級swagger相關依賴

<dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId><version>3.0.0</version><!-- 項目里沒用到這個google依賴的話 這段可以刪掉 --><exclusions><exclusion><groupId>com.google.guava</groupId><artifactId>guava</artifactId></exclusion></exclusions>
</dependency>
<dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger-ui</artifactId><version>3.0.0</version>
</dependency>
<dependency><groupId>com.github.xiaoymin</groupId><artifactId>knife4j-spring-boot-starter</artifactId><version>3.0.3</version>
</dependency><dependency><groupId>io.swagger</groupId><artifactId>swagger-annotations</artifactId><version>1.5.21</version>
</dependency>
<dependency><groupId>io.swagger</groupId><artifactId>swagger-models</artifactId><version>1.5.21</version>
</dependency>

三、swaggerConfig配置

springfoxHandlerProviderBeanPostProcessor方法是為了解決升級3.0.0后控制臺報錯“Failed to start bean 'documentationPluginsBootstrapper';”的問題,親測有用。

package com.wyzz.global.config;import com.wyzz.model.constant.SwaggerVersionConstant;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.ReflectionUtils;
import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.spring.web.plugins.WebFluxRequestHandlerProvider;
import springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider;
import springfox.documentation.swagger2.annotations.EnableSwagger2;import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;@Configuration
@EnableOpenApi
public class SwaggerConfig {/** 定義api接口包的掃描路徑 */private static  final String SWAGGER_SCAN_PACKAGE = "com.xxx.controller";/** 版本信息 */private static final String API_VERSION = "1.0.0";@Beanpublic BeanPostProcessor springfoxHandlerProviderBeanPostProcessor() {return new BeanPostProcessor() {@Overridepublic Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {if (bean instanceof WebMvcRequestHandlerProvider || bean instanceof WebFluxRequestHandlerProvider) {customizeSpringfoxHandlerMappings(getHandlerMappings(bean));}return bean;}private <T extends RequestMappingInfoHandlerMapping> void customizeSpringfoxHandlerMappings(List<T> mappings) {List<T> copy = mappings.stream().filter(mapping -> mapping.getPatternParser() == null).collect(Collectors.toList());mappings.clear();mappings.addAll(copy);}@SuppressWarnings("unchecked")private List<RequestMappingInfoHandlerMapping> getHandlerMappings(Object bean) {try {Field field = ReflectionUtils.findField(bean.getClass(), "handlerMappings");field.setAccessible(true);return (List<RequestMappingInfoHandlerMapping>) field.get(bean);} catch (IllegalArgumentException | IllegalAccessException e) {throw new IllegalStateException(e);}}};}@Beanpublic Docket createApi(){return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_PACKAGE)).paths(PathSelectors.any()).build();}private ApiInfo apiInfo(){return new ApiInfoBuilder().title("Server").description("API接口文檔").version(API_VERSION).termsOfServiceUrl("http://localhost:9090/v3").build();}//按版本分組@Beanpublic Docket v100(){return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).groupName("v1.0.0").select().apis(input -> {ApiVersion apiVersion = input.getHandlerMethod().getMethodAnnotation(ApiVersion.class);return apiVersion != null && Arrays.asList(apiVersion.group()).contains("v1.0.0");}).paths(PathSelectors.any()).build();}
}

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/88488.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/88488.shtml
英文地址,請注明出處:http://en.pswp.cn/web/88488.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Python-正則表達式-信息提取-滑動窗口-數據分發-文件加載及分析器-瀏覽器分析-學習筆記

序 欠4前年的一份筆記 &#xff0c;獻給今后的自己。 正則表達式 概述 正則表達式&#xff0c;Regular Expression&#xff0c;縮寫為regex、regexp、RE等。 正則表達式是文本處理極為重要的技術&#xff0c;用它可以對字符串按照某種規則進行檢索、替換。 1970年代&…

一文入門神經網絡:神經網絡概念初識

神經網絡的世界遠比你想象得更豐富多元。從基礎架構到前沿融合模型&#xff0c;我為你梳理了當前最值得關注的神經網絡類型&#xff0c;不僅包括那些“教科書級”的經典模型&#xff0c;也覆蓋了正在改變行業格局的新興架構。以下是系統分類與核心特點總結&#xff1a;一、基礎…

線上事故處理記錄

線上事故處理記錄 一、MySQL 導致的服務器 CPU 飆升 有一天&#xff0c;突然收到了服務器 CPU 飆升的告警信息&#xff0c;打開普羅米修斯查看 CPU 的使用情況&#xff0c;發現 CPU 確實飆升了&#xff0c;下面開始去進行問題定位了。 1. 首先連接到對應的服務器&#xff0c;然…

ParaCAD 筆記 png 圖紙標注數據集

ParaCAD-Dataset git lfs install git clone https://www.modelscope.cn/datasets/yuwenbonnie/ParaCAD-Dataset.git https://github.com/ParaCAD/ 不止100g 下個最小的 沒有三視圖

C#使用Semantic Kernel實現Embedding功能

1、背景 C#開發中&#xff0c;可以通過Semantic Kernel實現本地模型的調用和實現。 本地的Ollama的版本如下&#xff1a;安裝的Package如下&#xff1a;2、代碼實現 // See https://aka.ms/new-console-template for more information using Microsoft.Extensions.AI; using Mi…

轉轉APP逆向

APP版本 11.15.0 接口分析 # URL https://app.zhuanzhuan.com/zz/transfer/search# header cookie xxx x-zz-monitoring-metrics feMetricAntiCheatLevelV1 zztk user-agent Zhuan/11.15.0 (11015000) Dalvik/2.1.0 (Linux; U; Android 10; Pixel 3 Build/QQ3A.200805.001) z…

注解與反射的完美配合:Java中的聲明式編程實踐

注解與反射的完美配合&#xff1a;Java中的聲明式編程實踐 目錄 引言 核心概念 工作機制 實戰示例 傳統方式的痛點 注解反射的優勢 實際應用場景 最佳實踐 總結 引言 在現代Java開發中&#xff0c;我們經常看到這樣的代碼&#xff1a; Range(min 1, max 50)priva…

開源入侵防御系統——CrowdSec

1、簡介 CrowdSec 是一款現代化、開源、基于行為的入侵防御系統&#xff08;IDS/IPS&#xff09;&#xff0c;專為保護服務器、服務、容器、云原生應用而設計。它通過分析日志檢測可疑行為&#xff0c;并可基于社區協作共享惡意 IP 黑名單&#xff0c;從而實現分布式防御。 其…

imx6ull-裸機學習實驗13——串口格式化函數移植實驗

目錄 前言 格式化函數 實驗程序編寫 stdio文件夾 main.c Makefile修改 編譯下載 前言 在學習實驗12&#xff1a;imx6ull串口通信實驗&#xff0c;我們實現了 UART1 基本的數據收發功能&#xff0c;雖然可以用來調試程序&#xff0c;但是功能太單一了&#xff0c;只能輸出…

CCF-GESP 等級考試 2025年6月認證C++三級真題解析

1 單選題&#xff08;每題 2 分&#xff0c;共 30 分&#xff09;第1題 8位二進制原碼能表示的最小整數是&#xff1a;&#xff08; &#xff09;A. -127 B. -128 C. -255 …

【網絡安全】服務間身份認證與授權模式

未經許可,不得轉載。 文章目錄 問題背景用戶到服務的身份認證與授權系統對系統的通信服務與服務之間的通信需求分析Basic Auth(基本身份認證)優點缺點mTLS 證書認證優點缺點OAuth 2.0優點缺點JWS(JSON Web Signature)優點缺點結合 Open Policy Agent 的 JWS 方案優點缺點結…

【EGSR2025】材質+擴散模型+神經網絡相關論文整理隨筆(四)

An evaluation of SVBRDF Prediction from Generative Image Models for Appearance Modeling of 3D Scenes輸入3D場景的幾何和一張參考圖像&#xff0c;通過擴散模型和SVBRDF預測器獲取多視角的材質maps&#xff0c;這些maps最終合并成場景的紋理地圖集&#xff0c;并支持在任…

Grid網格布局完整功能介紹和示例演示

CSS Grid布局是一種強大的二維布局系統&#xff0c;可以將頁面劃分為行和列&#xff0c;精確控制元素的位置和大小。以下是其完整功能介紹和示例演示&#xff1a; 基本概念 網格容器&#xff08;Grid Container&#xff09;&#xff1a;應用display: grid的元素。網格項&#x…

學習C++、QT---21(QT中QFile庫的QFile讀取文件、寫入文件的講解)

每日一言把大目標拆成小步&#xff0c;每天前進一點點&#xff0c;終會抵達終點。QFile讀取文件我們記事本要進行讀取文件、寫入文件、等等的操作&#xff0c;那么這個時候我們的QT有一個QT類叫做QFile這個類的話是專門對于文件操作的&#xff0c;所以我們來學習我們在QT的幫助…

AD736ARZ-R7精密真有效值轉換器 高精度測量的首選方案

AD736ARZ-R7精密轉換器產品概述AD736ARZ-R7是ADI&#xff08;Analog Devices Inc.&#xff09;推出的一款低功耗、高精度的真有效值&#xff08;RMS&#xff09;轉直流&#xff08;DC&#xff09;轉換器&#xff0c;采用SOIC-8封裝&#xff0c;適用于需要精確測量交流或復雜波形…

【web應用】若依框架前端報表制作與導出全攻略(ECharts + html2canvas + jsPDF)

文章目錄前言一、ECharts準備工作1. 檢查ECharts安裝2. 導入ECharts3. 創建餅圖組件4. 模板部分二、報表導出功能實現1. 安裝依賴2. 導入依賴3. 完整導出函數實現4. 樣式優化三、完整組件實現四、常見問題與解決方案1. 圖表截圖不完整或模糊2. 圖表背景透明3. 導出PDF中文亂碼4…

vue3+express聯調接口時報“\“username\“ is required“問題

我用node .js的express框架寫的登錄接口&#xff0c;發現postman可以調通&#xff0c;但是vue3前端報錯vue3我發現是我后端node.js的app.js入口文件中配置的解析前端參數的解析中間件和前端請求頭中的Content-Type配置不一致的原因 解決方案 因為我后端配置解析表單數據的中間件…

《月亮與六便士》:天才的背叛與凡人救贖的殘酷辯證法

當滿地六便士成了庸人的火葬場??毛姆筆下的斯特里克蘭德&#xff0c;是一把捅穿中產幻夢的利刃。這個拋妻棄子、背叛友人的證券經紀人&#xff0c;在倫敦客廳的茶香與銀勺碰撞聲中&#xff0c;突然聽見了遠方的驚雷——“我必須畫畫”。如書中所言&#xff1a;??“在滿地都…

vue2往vue3升級需要注意的點(個人建議非必要別直接升級)

將 Vue 2 項目升級到 Vue 3 的過程中&#xff0c;需要重點關注以下幾個難點和關鍵點&#xff1a; 建議小項目直接用vue3重寫更快&#xff0c;bug更少 文章目錄1. **Composition API 的學習與應用**2. **全局 API 的變更**3. **模板語法的兼容性變化**4. **組件選項和生命周期的…

聚焦數據資源建設與應用,浙江省質科院赴景聯文科技調研交流

7月10日上午&#xff0c;浙江省質科院標準化中心副主任蔣建平、應珊婷等一行領導帶隊蒞臨景聯文科技調研指導工作。雙方圍繞工業數據展開深度交流。座談會上&#xff0c;景聯文科技詳細匯報了數據資源建設與應用方面的成果與規劃&#xff0c;介紹了公共數據授權運營與對外合作的…