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

如何解决org.springframework.security:spring-security-oauth2-server依赖版本缺失问题?

解决Maven依赖解析问题:org.springframework.security:spring-security-oauth2-server版本缺失

问题根源

你配置的org.springframework.security:spring-security-oauth2-server依赖未指定版本号,Maven无法确定要拉取的包版本,因此抛出版本缺失的错误。

解决方法

方法一:借助Spring Boot依赖管理自动适配版本

如果你的项目基于Spring Boot,Spring Boot父POM已对Spring Security系列依赖做了版本统一管理,只需确保项目正确关联Spring Boot的依赖管理:

  1. 若未继承Spring Boot父POM,添加以下配置到你的POM文件:
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.2.0</version> <!-- 替换为你实际使用的Spring Boot版本 -->
    <relativePath/>
</parent>
  1. 若无法继承父POM,可通过依赖管理BOM引入:
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>3.2.0</version> <!-- 替换为你实际使用的Spring Boot版本 -->
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

完成后,spring-security-oauth2-server依赖会自动使用Spring Boot适配的版本,无需手动添加<version>标签。

方法二:手动指定依赖版本

如果需要自定义版本或不使用Spring Boot依赖管理,直接在依赖中添加版本号:

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-oauth2-server</artifactId>
    <version>6.2.0</version> <!-- 替换为与你的项目兼容的版本,Spring Boot 3.x对应Spring Security 6.x -->
</dependency>

后续操作

修改配置后,执行mvn clean install或mvn dependency:resolve命令,让Maven重新拉取依赖并清理本地仓库缓存。同时检查Maven镜像配置,确保能访问包含该依赖的仓库。

内容的提问来源于stack exchange,提问作者Okpara Ifeanyi Ekene

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 09:12:39