You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何排除org.springframework.cloud引入的spring-security-oauth2-autoconfigure依赖版本

解决方案

你遇到的是Maven依赖管理的优先级问题,spring-cloud-dependencies里托管的spring-security-oauth2-autoconfigure版本优先级更高,所以覆盖了你期望引入的版本,可通过以下两种方式解决:

方案1:在dependencyManagement中优先声明指定版本(推荐)

Maven的dependencyManagement会按照声明先后顺序判断版本优先级,你只需要把指定版本的依赖放在spring-cloud-dependencies之前声明即可,修改后的dependencyManagement配置如下:

<dependencyManagement>
    <dependencies>
        <!-- 优先声明需要的oauth2 autoconfigure版本,会覆盖后续spring cloud托管的版本 -->
        <dependency>
            <groupId>org.springframework.security.oauth.boot</groupId>
            <artifactId>spring-security-oauth2-autoconfigure</artifactId>
            <version>2.1.9.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>2020.0.3</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

该方案可以全项目统一管理该依赖版本,后续其他模块引入该依赖不需要重复写版本号。

方案2:直接在依赖声明处指定版本

你也可以直接在<dependencies>节点下的对应依赖里显式指定版本,这种方式优先级高于所有dependencyManagement的托管版本:

<dependency>
   <groupId>org.springframework.security.oauth.boot</groupId>
   <artifactId>spring-security-oauth2-autoconfigure</artifactId>
   <version>2.1.9.RELEASE</version>
</dependency>

修改完成后可执行mvn dependency:tree命令查看该依赖的实际生效版本,确认是否已经变为2.1.9.RELEASE。

内容的提问来源于stack exchange,提问作者hello world

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 22:54:01