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

Maven依赖解析失败:spring-cloud-starter-netflix-eureka-server等依赖未找到

问题:Maven无法解析Spring Cloud依赖及Eureka Server依赖

父项目POM文件内容

<properties>
    <maven.compiler.source>17</maven.compiler.source>
    <maven.compiler.target>17</maven.compiler.target>
    <spring-cloud-version>2021.0.2</spring-cloud-version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<modules>
    <module>product-service</module>
    <module>order-service</module>
    <module>inventory-service</module>
    <module>discovery-service</module>
</modules>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>testcontainers-bom</artifactId>
            <version>1.17.6</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

discovery-service子项目POM文件内容

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-autoconfigure</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
    </dependency>
</dependencies>

遇到的错误

  • 无法解析导入POM:org.springframework.cloud:spring-cloud-dependencies:pom:${spring-cloud.version} 在之前的尝试中未在https://repo.maven.apache.org/maven2找到。
  • org.springframework.cloud:spring-cloud-starter-netflix-eureka-server:jar:unknown 在之前的尝试中未在https://repo.maven.apache.org/maven2找到。

已尝试的方法

将父POM中<version>${spring-cloud.version}</version>直接替换为2021.0.2,问题仍未解决。


解决方案

1. 补全Spring Boot依赖管理并确认版本兼容性

Spring Cloud 2021.0.2(Jubilee版本)必须搭配Spring Boot 2.6.x系列使用,父POM中缺失Spring Boot的依赖管理会导致依赖解析失败。在父POM的<dependencyManagement>中添加Spring Boot依赖:

<dependencyManagement>
    <dependencies>
        <!-- 先引入Spring Boot依赖管理 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>2.6.13</version> <!-- 与Spring Cloud 2021.0.2兼容的稳定版 -->
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <!-- 保留原有依赖 -->
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>testcontainers-bom</artifactId>
            <version>1.17.6</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring-cloud-version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

同时确保子项目discovery-service的POM正确继承父项目,在子POM最顶部添加:

<parent>
    <groupId>你的父项目groupId</groupId> <!-- 替换为实际父项目groupId -->
    <artifactId>你的父项目artifactId</artifactId> <!-- 替换为实际父项目artifactId -->
    <version>你的父项目版本</version> <!-- 替换为实际父项目版本 -->
</parent>

2. 清理Maven本地缓存

本地仓库可能存在损坏的依赖文件,执行命令强制更新并重新下载依赖:

mvn clean install -U

3. 检查Maven镜像配置

如果使用了自定义Maven镜像,需确认镜像仓库同步了Spring Cloud 2021.0.2版本的依赖,可临时切换回Maven中央仓库排查问题。


内容的提问来源于stack exchange,提问作者satyajeet jha

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.07 07:15:35