1.背景

版本比对检测原理:检查当前系统中spring-security-web版本是否在漏洞版本范围内|版本比对检测结果:- spring-security-web
当前安装版本:5.2.1.RELEASE
需要升级到 5.5.7、5.6.4 及以上版本,因为pom中找不到直接引用的位置,所以加入以下依赖将spring-security-web版本强制升级到5.5.7

    <!-- 修复spring-security-web版本漏洞 -->
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>5.5.7</version>
    </dependency>

启动时报错,报错内容如下:

***************************
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.原因分析

可以发现spring包版本不兼容导致该问题,理论上是spring-security-web是在某一个jar引入,单独改了spring-security-web的版本,导致这个jar中的配套代码不兼容导致的问题

3.解决方式

将spring-boot-dependencies的2.1.17.RELEASE升级到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强制覆盖版本即可
        <!-- 修复spring-security-web版本漏洞 -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>5.5.7</version>
        </dependency>

4.解决思路:

因为单独改了spring-security-web的版本,导致这个jar中的配套代码不兼容导致的问题,所以首要问题需要找到spring-security-web由哪个jar引入的

4.1查询Maven 项目查找 jar 包是由哪个依赖引入的

直接使用mvn dependency:tree可以查看项目完整的依赖树。

  1. 命令格式
mvn dependency:tree -Dverbose -Dincludes=要查询的内容(groupId:artifactId)

-dependency:tree:表示树状显示。
-Dverbose:表示可以显示所有的引用,包括因为多次引用重复而忽略的。
-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中执行之后依赖层级如下图

在这里插入图片描述

4.3spring-security-web是由spring-boot-starter-security引入的

spring-security-web是由spring-boot-starter-security引入的,版本是2.1.17.RELEASE,搜spring-boot-starter-security发现又是使用的spring-boot-dependencies-2.1.17.RELEASE.pom的版本
在这里插入图片描述

4.3spring-boot-starter-security版本是继承spring-boot-dependencies的版本

在全局搜spring-boot-dependencies的版本,发现果然是2.1.17.RELEASE,到此,所有的依赖层级都找到了,那开始猜,是不是spring-boot-dependencies版本太低了,spring-security-web的版本太高了导致的不兼容,spring-security-web版本不能调低,只能升级spring-boot-dependencies的版本,在maven仓库查找spring-boot-dependencies版本,逐级测试,发现2.2.2.RELEASE可以支持,所以问题到此解决.
在这里插入图片描述

参考:
Maven 项目查找 jar 包是由哪个依赖引入的

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐