搭建srping-cloud项目过程中,出现上面的报错

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

在这里插入图片描述

解决办法有两种。

第一种:

 <dependencies>
        <!--eureka-server-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
            <version>2.1.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

第一种方法不建议,因为有spring boot 和 spring cloud 版本之间有对应关系。

网上看了很多版本介绍的spring boot 和spring cloud之间的对应关系。需要注意的是你用的spring-cloud是netflix还是alibaba的,他们之间的版本不完全相同。

最好看官网的:https://spring.io/projects/spring-cloud#learn
在这里插入图片描述

我们点开其中一个,可以看到当前版本支持spring boot是3.0.9
在这里插入图片描述

然后往下拉,看到当前对应的spring-cloud-netflix的版本是 4.0.4-SNAPSHOT
在这里插入图片描述

第二种:

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

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-parent</artifactId>
                <version>Greenwich.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

这里面的Greenwich是spring-cloud当前版本的别称,这个别称没有查到在哪里查,只查到了下面的这个表格。

pring Cloud Version			Spring Boot Version
2022.0.x aka Kilburn			3.0.x
2021.0.x aka Jubilee			2.6.x, 2.7.x (Starting with 2021.0.3)
2020.0.x aka Ilford				2.4.x, 2.5.x (Starting with 2020.0.3)
Hoxton									2.2.x, 2.3.x (Starting with SR5)
Greenwich							2.1.x
Finchley								2.0.x
Edgware								1.5.x
Dalston								1.5.x

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐