解決Spring?Security升級(jí)到5.5.7、5.6.4及以上啟動(dòng)報(bào)錯(cuò)出現(xiàn)版本不兼容的問題
1.背景
版本比對(duì)檢測(cè)原理:檢查當(dāng)前系統(tǒng)中spring-security-web版本是否在漏洞版本范圍內(nèi)|版本比對(duì)檢測(cè)結(jié)果:- spring-security-web
當(dāng)前安裝版本:5.2.1.RELEASE
需要升級(jí)到 5.5.7、5.6.4 及以上版本,因?yàn)閜om中找不到直接引用的位置,所以加入以下依賴將spring-security-web版本強(qiáng)制升級(jí)到5.5.7
<!-- 修復(fù)spring-security-web版本漏洞 --> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-web</artifactId> <version>5.5.7</version> </dependency>
啟動(dòng)時(shí)報(bào)錯(cuò),報(bào)錯(cuò)內(nèi)容如下:
***************************
APPLICATION FAILED TO START
***************************Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.security.web.util.matcher.OrRequestMatcher.<init>(OrRequestMatcher.java:43)
The following method did not exist:
org.springframework.util.Assert.noNullElements(Ljava/util/Collection;Ljava/lang/String;)V
The method's class, org.springframework.util.Assert, is available from the following locations:
jar:file:/C:/Users/sutpc/.m2/repository/org/springframework/spring-core/5.1.18.RELEASE/spring-core-5.1.18.RELEASE.jar!/org/springframework/util/Assert.class
It was loaded from the following location:
file:/C:/Users/sutpc/.m2/repository/org/springframework/spring-core/5.1.18.RELEASE/spring-core-5.1.18.RELEASE.jar
2.原因分析
可以發(fā)現(xiàn)spring包版本不兼容導(dǎo)致該問題
理論上是spring-security-web是在某一個(gè)jar引入
單獨(dú)改了spring-security-web的版本
導(dǎo)致這個(gè)jar中的配套代碼不兼容導(dǎo)致的問題
3.解決方式
將spring-boot-dependencies的2.1.17.RELEASE升級(jí)到2.2.2.RELEASE <!-- SpringBoot的依賴配置--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <!-- <version>2.1.17.RELEASE</version>--> <version>2.2.2.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> 在pom的最后直接使用spring-security-web的5.5.7強(qiáng)制覆蓋版本即可 <!-- 修復(fù)spring-security-web版本漏洞 --> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-web</artifactId> <version>5.5.7</version> </dependency>
4.解決思路
因?yàn)閱为?dú)改了spring-security-web的版本
導(dǎo)致這個(gè)jar中的配套代碼不兼容導(dǎo)致的問題
所以首要問題需要找到spring-security-web由哪個(gè)jar引入的
4.1查詢Maven 項(xiàng)目查找 jar 包是由哪個(gè)依賴引入的
直接使用mvn dependency:tree可以查看項(xiàng)目完整的依賴樹。
1.命令格式
mvn dependency:tree -Dverbose -Dincludes=要查詢的內(nèi)容(groupId:artifactId)
-dependency:tree
:表示樹狀顯示。-Dverbose
:表示可以顯示所有的引用,包括因?yàn)槎啻我弥貜?fù)而忽略的。-Dincludes
:可以制定查詢條件
spring-security-web的groupId和artifactId為:
groupId: org.springframework.security artifactId: spring-security-web 所以命令為 mvn dependency:tree -Dverbose -Dincludes=org.springframework.security:spring-security-web
4.2在idea的Teminal中執(zhí)行之后依賴層級(jí)如下圖
4.3spring-security-web是由spring-boot-starter-security引入的
spring-security-web是由spring-boot-starter-security引入的
版本是2.1.17.RELEASE
搜spring-boot-starter-security發(fā)現(xiàn)又是使用的spring-boot-dependencies-2.1.17.RELEASE.pom的版本
4.4spring-boot-starter-security版本是繼承spring-boot-dependencies的版本
在全局搜spring-boot-dependencies的版本,
發(fā)現(xiàn)果然是2.1.17.RELEASE,到此,所有的依賴層級(jí)都找到了,
那開始猜,是不是spring-boot-dependencies版本太低了,
spring-security-web的版本太高了導(dǎo)致的不兼容,
spring-security-web版本不能調(diào)低,只能升級(jí)spring-boot-dependencies的版本,
在maven倉庫查找spring-boot-dependencies版本,
逐級(jí)測(cè)試,發(fā)現(xiàn)2.2.2.RELEASE可以支持,所以問題到此解決.
參考:Maven 項(xiàng)目查找 jar 包是由哪個(gè)依賴引入的
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
idea微服務(wù)項(xiàng)目服務(wù)如何顯示在同一窗口
本文介紹了如何在微服務(wù)項(xiàng)目導(dǎo)入時(shí)將所有服務(wù)加入同一窗口中,解決啟動(dòng)項(xiàng)目服務(wù)時(shí)顯示不全的問題,通過點(diǎn)擊左上角的View,選擇ToolWindows,然后選擇Services,使用快捷鍵Alt+8,選擇Spring Boot,就可以將所有服務(wù)加到同一窗口中2025-02-02IDEA中創(chuàng)建maven項(xiàng)目webapp目錄無法識(shí)別即未被標(biāo)識(shí)的解決辦法
在學(xué)習(xí)SpringMVC課程中,基于IDEA新建maven項(xiàng)目模塊后,webapp目錄未被標(biāo)識(shí),即沒有小藍(lán)點(diǎn)的圖標(biāo)顯示,所以本文給大家介紹了IDEA中創(chuàng)建maven項(xiàng)目webapp目錄無法識(shí)別即未被標(biāo)識(shí)的解決辦法,需要的朋友可以參考下2024-03-03Java web入門指南之在Idea上創(chuàng)建Java web項(xiàng)目
好多書上的JavaWeb教程都是Eclipse以及MyEclipse,當(dāng)然這里不論IDE的好壞,下面這篇文章主要給大家介紹了關(guān)于Java web入門指南之在Idea上創(chuàng)建Java web項(xiàng)目的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-06-06使用Spring處理x-www-form-urlencoded方式
這篇文章主要介紹了使用Spring處理x-www-form-urlencoded方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-11-11Java中的CGLIB動(dòng)態(tài)代理的使用及原理詳解
這篇文章主要介紹了Java中的CGLIB動(dòng)態(tài)代理的使用及原理詳解,CGLIB是一個(gè)功能強(qiáng)大,高性能的代碼生成包,它為沒有實(shí)現(xiàn)接口的類提供代理,為JDK的動(dòng)態(tài)代理提供了很好的補(bǔ)充,需要的朋友可以參考下2023-09-09MybatisPlus 插入或更新數(shù)據(jù)時(shí)自動(dòng)填充更新數(shù)據(jù)解決方案
本文主要介紹了MybatisPlus 插入或更新數(shù)據(jù)時(shí)自動(dòng)填充更新數(shù)據(jù)解決方案,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09Java實(shí)戰(zhàn)之藥品管理系統(tǒng)的實(shí)現(xiàn)
這篇文章主要介紹了利用Java實(shí)現(xiàn)的藥品管理系統(tǒng),本項(xiàng)目屬于前后端分離的項(xiàng)目,分為兩個(gè)角色藥品管理員和取藥處人員,感興趣的小伙伴可以學(xué)習(xí)一下2022-04-04