吐血推荐--SpringBoot与SpringCloud的版本对应说明,兼容说明

2021/9/17 6:05:11

本文主要是介绍吐血推荐--SpringBoot与SpringCloud的版本对应说明,兼容说明,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

一、为啥要讲这个版本对应

首先先说下我此次记录问题的SpringBoot 版本:2.5.4

由于最近刚开始接触SpringBoot,在加载Eureak的客户端依赖包的时候,出现了下面的错误,提示找不到依赖

Cannot resolve org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:unknown

 

 

 

当时怀疑应该是SpringBoot 版本:2.5.4版本下面没有这个jar包,于是先通过阿里云的maven私服去查找了下,

 

 

 

然后尝试去掉版本搜了下,大概有501个

 

 

 

于是找了一个相近的版本,使用的是2.2.6.RELEASE,然后刷新maven加载

 

 

 

加载成功后,spring-cloud-starter-netflix-eureka-client依赖包已经下载下来

 

 

 

于是乎,满心欢喜的去运行应用,结果啪啪打脸啊,比任何时候都响,那是响彻天空,响彻万里啊!!!

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configurationPropertiesBeans' defined in class path resource [org/springframework/cloud/autoconfigure/ConfigurationPropertiesRebinderAutoConfiguration.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.context.properties.ConfigurationPropertiesBeans] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:579) ~[spring-beans-5.3.9.jar:5.3.9]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[spring-beans-5.3.9.jar:5.3.9]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.9.jar:5.3.9]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.9.jar:5.3.9]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.9.jar:5.3.9]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:213) ~[spring-beans-5.3.9.jar:5.3.9]
	at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:270) ~[spring-context-5.3.9.jar:5.3.9]
	at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:762) ~[spring-context-5.3.9.jar:5.3.9]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:567) ~[spring-context-5.3.9.jar:5.3.9]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) ~[spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) ~[spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:143) [spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:212) [spring-cloud-context-2.2.6.RELEASE.jar:2.2.6.RELEASE]
	at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:117) [spring-cloud-context-2.2.6.RELEASE.jar:2.2.6.RELEASE]
	at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:74) [spring-cloud-context-2.2.6.RELEASE.jar:2.2.6.RELEASE]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) [spring-context-5.3.9.jar:5.3.9]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) [spring-context-5.3.9.jar:5.3.9]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) [spring-context-5.3.9.jar:5.3.9]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131) [spring-context-5.3.9.jar:5.3.9]
	at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:82) [spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:63) [spring-boot-2.5.4.jar:2.5.4]
	at java.util.ArrayList.forEach(ArrayList.java:1259) ~[na:1.8.0_281]
	at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:117) [spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:111) [spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:62) [spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:374) ~[spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:332) ~[spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) ~[spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332) ~[spring-boot-2.5.4.jar:2.5.4]
	at com.joshua317.blog.BlogApplication.main(BlogApplication.java:12) ~[classes/:na]
Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.context.properties.ConfigurationPropertiesBeans] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]
	at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:481) ~[spring-core-5.3.9.jar:5.3.9]
	at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321) ~[spring-core-5.3.9.jar:5.3.9]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.buildLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:232) ~[spring-beans-5.3.9.jar:5.3.9]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.findLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:210) ~[spring-beans-5.3.9.jar:5.3.9]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(InitDestroyAnnotationBeanPostProcessor.java:149) ~[spring-beans-5.3.9.jar:5.3.9]
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(CommonAnnotationBeanPostProcessor.java:294) ~[spring-context-5.3.9.jar:5.3.9]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:1098) ~[spring-beans-5.3.9.jar:5.3.9]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:576) ~[spring-beans-5.3.9.jar:5.3.9]
	... 30 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
	at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_281]
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[na:1.8.0_281]
	at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[na:1.8.0_281]
	at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463) ~[spring-core-5.3.9.jar:5.3.9]
	... 37 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[na:1.8.0_281]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:418) ~[na:1.8.0_281]
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355) ~[na:1.8.0_281]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ~[na:1.8.0_281]
	... 41 common frames omitted

2021-09-16 10:58:56.852 ERROR 15524 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configurationPropertiesBeans' defined in class path resource [org/springframework/cloud/autoconfigure/ConfigurationPropertiesRebinderAutoConfiguration.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.context.properties.ConfigurationPropertiesBeans] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:579) ~[spring-beans-5.3.9.jar:5.3.9]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[spring-beans-5.3.9.jar:5.3.9]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.9.jar:5.3.9]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.9.jar:5.3.9]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.9.jar:5.3.9]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:213) ~[spring-beans-5.3.9.jar:5.3.9]
	at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:270) ~[spring-context-5.3.9.jar:5.3.9]
	at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:762) ~[spring-context-5.3.9.jar:5.3.9]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:567) ~[spring-context-5.3.9.jar:5.3.9]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) [spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) [spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) [spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:143) ~[spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:212) ~[spring-cloud-context-2.2.6.RELEASE.jar:2.2.6.RELEASE]
	at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:117) ~[spring-cloud-context-2.2.6.RELEASE.jar:2.2.6.RELEASE]
	at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:74) ~[spring-cloud-context-2.2.6.RELEASE.jar:2.2.6.RELEASE]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) ~[spring-context-5.3.9.jar:5.3.9]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) ~[spring-context-5.3.9.jar:5.3.9]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) ~[spring-context-5.3.9.jar:5.3.9]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131) ~[spring-context-5.3.9.jar:5.3.9]
	at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:82) ~[spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:63) ~[spring-boot-2.5.4.jar:2.5.4]
	at java.util.ArrayList.forEach(ArrayList.java:1259) ~[na:1.8.0_281]
	at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:117) ~[spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:111) ~[spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:62) ~[spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:374) [spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:332) [spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) [spring-boot-2.5.4.jar:2.5.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332) [spring-boot-2.5.4.jar:2.5.4]
	at com.joshua317.blog.BlogApplication.main(BlogApplication.java:12) [classes/:na]
Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.context.properties.ConfigurationPropertiesBeans] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]
	at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:481) ~[spring-core-5.3.9.jar:5.3.9]
	at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321) ~[spring-core-5.3.9.jar:5.3.9]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.buildLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:232) ~[spring-beans-5.3.9.jar:5.3.9]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.findLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:210) ~[spring-beans-5.3.9.jar:5.3.9]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(InitDestroyAnnotationBeanPostProcessor.java:149) ~[spring-beans-5.3.9.jar:5.3.9]
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(CommonAnnotationBeanPostProcessor.java:294) ~[spring-context-5.3.9.jar:5.3.9]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:1098) ~[spring-beans-5.3.9.jar:5.3.9]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:576) ~[spring-beans-5.3.9.jar:5.3.9]
	... 30 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
	at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_281]
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[na:1.8.0_281]
	at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[na:1.8.0_281]
	at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463) ~[spring-core-5.3.9.jar:5.3.9]
	... 37 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[na:1.8.0_281]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:418) ~[na:1.8.0_281]
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355) ~[na:1.8.0_281]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ~[na:1.8.0_281]
	... 41 common frames omitted


Process finished with exit code 1

 

 

 

经过多方调研,考证,最终证实原来SpringBoot版本要想使用SpringCloud里面的依赖包,需要版本兼容才可以,至于如何考证,如何证实,期间走了多少弯路,这里就不赘述了,宝宝心里苦,但是宝宝不说。苦就苦我一人吧,以后大家遇到了知道怎么回事,避免踩这样的坑就行了。希望初学者,也能注意此处的问题,在引入依赖包的时候,要找好对应的版本。如果项目在初始化时正确,然后编译时报错的,基本上都是依赖包导致的问题。

注意pom.xml里面是否有dependencyManagement版本管理的设置,因为这块是会识别并加载所需要的依赖版本,比如我要加载spring-cloud-starter-netflix-eureka-client,首先确定好你的SpringBoot版本是否兼容依赖的SpringCloud版本,其次是否设置了spring-cloud.version,接着确认是否设置了dependencyManagement下面的spring-cloud-dependencies依赖,最后确认好要加载的spring-cloud-starter-netflix-eureka-client,这样最终保证你所需要的依赖包能够争取无误的加载下来。如下面的代码示例:

<properties>
	<java.version>1.8</java.version>
	<spring-cloud.version>2020.0.3</spring-cloud.version>
</properties>
<dependencyManagement>
	<dependencies>
		<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>
	
<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
</dependencies>

 

 

 

一定要确保SpringBoot版本和Spring Cloud版本的兼容性

二、如何查看版本对应

2.1 查看Spring Cloud版本

首先进入srping官网,https://spring.io/,然后找到Spring Cloud页面

 

 

 

根据官方说明我们可以知道,可以直接创建一个Spring Cloud 项目,也可以在Spring Boot应用的基础上添加Spring Cloud

Getting Started
Generating A New Spring Cloud Project
The easiest way to get started is visit start.spring.io, select your Spring Boot version and the Spring Cloud projects you want to use. This will add the corresponding Spring Cloud BOM version to your Maven/Gradle file when you generate the project.

Adding Spring Cloud To An Existing Spring Boot Application
If you an existing Spring Boot app you want to add Spring Cloud to that app, the first step is to determine the version of Spring Cloud you should use. The version you use in your app will depend on the version of Spring Boot you are using.

The table below outlines which version of Spring Cloud maps to which version of Spring Boot.

入门
生成一个新的 Spring Cloud 项目
最简单的入门方法是访问start.spring.io,选择您的 Spring Boot 版本和您要使用的 Spring Cloud 项目。这将在您生成项目时将相应的 Spring Cloud BOM 版本添加到您的 Maven/Gradle 文件中。

将 Spring Cloud 添加到现有的 Spring Boot 应用程序
如果您想要将 Spring Cloud 添加到该应用程序的现有 Spring Boot 应用程序,第一步是确定您应该使用的 Spring Cloud 版本。您在应用中使用的版本取决于您使用的 Spring Boot 版本。

下表概述了 Spring Cloud 的哪个版本映射到 Spring Boot 的哪个版本。


 

 

 

同时要注意,下面这些已达到生命周期终止状态,不再受支持。

Spring Cloud Dalston, Edgware, Finchley, and Greenwich have all reached end of life status and are no longer supported.

Spring Cloud Dalston、Edgware、Finchley 和 Greenwich 都已达到生命周期终止状态,不再受支持。

点击最新版本https://spring.io/projects/spring-cloud#learn,我们可以看下对应的说明文档:https://docs.spring.io/spring-cloud/docs/current/reference/html/

 

 

 

可以看到,Spring Cloud版本是2020.0.3,是基于Supported Boot Version: 2.4.6

 

 

 

2.2 引入Spring Cloud版本

既然现在知道要使用哪个版本系列以及该版本系列的最新服务版本,我们可以将 Spring Cloud BOM 添加到应用程序中。修改pom.xml文件

<properties>
    <spring.cloud-version>Hoxton.SR8</spring.cloud-version>
</properties>
<dependencyManagement>
    <dependencies>
        <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>

注意:

发布系列包含 spring-cloud-dependencies和 spring-cloud-starter-parent. 我们可以像使用父对象一样使用spring-boot-starter-parent(如果你使用的是 Maven)。如果只需要依赖管理,“依赖”版本是同一事物的仅 BOM 版本(它只包含依赖管理,没有插件声明或对 Spring 或 Spring Boot 的直接引用)。如果使用的是 Spring Boot 父 POM,那么可以使用 Spring Cloud 中的 BOM。反之:使用 Cloud parent 使得不可能或至少不可靠,也使用 Boot BOM 来更改 Spring Boot 及其依赖项的版本。

就像 Spring Boot 一样,许多 Spring Cloud 项目都包含 starters,你可以将其添加为依赖项,以将各种云原生功能添加到您的项目中。在许多情况下,许多功能纯粹是通过将 starter 添加到类路径来启用的。起始名称记录在各个项目中。下面是一个示例,说明如何通过maven将 Spring Cloud Config Client 和 Spring Cloud Netflix Eureka 客户端添加到您的应用程序中。

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-config</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
    ...
</dependencies>

三、版本对应关系

官方的对应关系

版本关系对应地址:https://spring.io/projects/spring-cloud

Release TrainBoot Version
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

Spring Boot的版本以数字表示。例如:Spring Boot 2.3.12.RELEASE --> 主版本.次版本.增量版本(Bug修复) 下面是版本号介绍:

  • Alpha:不建议使用,主要是以实现软件功能为主,通常只在软件开发者内部交流,Bug较多;
  • Beta:该版本相对于α版已有了很大的改进,消除了严重的错误,但还是存在着一些缺陷,需要经过多次测试来进一步消除;
  • GA:General Availability,正式版本,官方推荐使用此版本,在国外都是用GA来说明release版本;
  • M:又叫里程碑版本,表示该版本较之前版本有功能上的重大更新;
  • PRE(不建议使用):预览版,内部测试版,主要是给开发人员和测试人员测试和找BUG用的;
  • Release:最终版本,Release不会以单词形式出现在软件封面上,取而代之的是符号(R);
  • RC:该版本已经相当成熟了,基本上不存在导致错误的BUG,与即将发行的正式版相差无几;
  • SNAPSHOT:快照版,可以稳定使用,且仍在继续改进版本。
  • SR.X 修正版,服务版本,当项目发布积累到一定程度,需要修复该版本中的某个错误后以此来命名,X表示数字。

四、举例说明如何找对应的版本

1.springCloud官方提供最准确的springCloud,springBoot版本对应关系

可通过如下网址查看:

https://start.spring.io/actuator/info

2.可以通过具体的Spring Cloud版本,然后看下该版本是基于哪个Srping Boot版本构建的

https://spring.io/projects/spring-cloud#learn

 

 

 

 

 

 

3.可以通过Spring Cloud发布的说明进行查看

地址为:https://github.com/spring-cloud/spring-cloud-release/wiki

 

 

 

4.在项目创建时,确定好自己要加载的依赖包

这种方式也是比较推荐的方式,在项目创建的时候,已经选好自己要加载的依赖包,避免不必要的麻烦。

创建项目的地址:https://start.spring.io/

 

 

 

五、实战

比如我们在Spring Boot项目的基础上,需要加载Spring Cloud里面的依赖包spring-cloud-starter-netflix-eureka-client,我们需要注意以下几个地方:

主要是pom.xml文件里面的这4个地方

(1)Spring Boot 版本

<parent>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-parent</artifactId>
    <version>2.5.4</version>
	<relativePath/> <!-- lookup parent from repository -->
</parent>

(2)Spring Cloud版本

<properties>
	<java.version>1.8</java.version>
	<spring-cloud.version>2020.0.3</spring-cloud.version>
</properties>

注意:当然Spring Boot 版本和Spring Cloud的版本的兼容选择,依然要参考上面提到的方法

(3)dependencyManagement设置,这个地方很重要哦!

<dependencyManagement>
	<dependencies>
		<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>

(4)Spring Cloud的包加载,比如spring-cloud-starter-netflix-eureka-client

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

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
</dependencies>

六、附录

这个主要在解决问题的过程中,搜集到的一些对应关系,附在后面,供大家参考

序号版本对应
1 <spring-boot.version>2.4.2</spring-boot.version> <spring-cloud.version>2020.0.0</spring-cloud.version>
2 <spring-boot.version>2.4.1</spring-boot.version> <spring-cloud.version>2020.0.0-M6</spring-cloud.version>
3 <spring-boot.version>2.4.0</spring-boot.version> <spring-cloud.version>2020.0.0-M6</spring-cloud.version>
4 <spring-boot.version>2.3.2.RELEASE</spring-boot.version> <spring-cloud.version>Greenwich.SR2</spring-cloud.version>
spring-cloud依赖spring-boot依赖
Finchley.M2 >=2.0.0.M3 and <2.0.0.M5
Finchley.M3 >=2.0.0.M5 and <=2.0.0.M5
Finchley.M4 >=2.0.0.M6 and <=2.0.0.M6
Finchley.M5 >=2.0.0.M7 and <=2.0.0.M7
Finchley.M6 >=2.0.0.RC1 and <=2.0.0.RC1
Finchley.M7 >=2.0.0.RC2 and <=2.0.0.RC2
Finchley.M9 >=2.0.0.RELEASE and <=2.0.0.RELEASE
Finchley.RC1 >=2.0.1.RELEASE and <2.0.2.RELEASE
Finchley.RC2 >=2.0.2.RELEASE and <2.0.3.RELEASE
Finchley.BUILD-SNAPSHOT >=2.0.999.BUILD-SNAPSHOT and <2.1.0.M3
Greenwich.M1 >=2.1.0.M3 and <2.1.0.RELEASE
Greenwich.SR6 >=2.1.0.RELEASE and <2.1.999.BUILD-SNAPSHOT
Greenwich.BUILD-SNAPSHOT >=2.1.999.BUILD-SNAPSHOT and <2.2.0.M4
Hoxton.SR9 >=2.2.0.M4 and <2.3.7.BUILD-SNAPSHOT
Hoxton.BUILD-SNAPSHOT >=2.3.7.BUILD-SNAPSHOT and <2.4.0.M1
2020.0.0-M3 >=2.4.0.M1 and <=2.4.0.M1
2020.0.0-M4 >=2.4.0.M2 and <=2.4.0-M3
2020.0.0-M5 >=2.4.0.M4 and <2.4.1-SNAPSHOT
2020.0.0-SNAPSHOT >=2.4.1-SNAPSHOT
spring-cloud-alibaba依赖spring-boot依赖
2.2.1.RELEASE >=2.2.0.RELEASE and <2.3.0.M1
Spring CloudSpring Boot
Angel版本 兼容Spring Boot 1.2.x
Brixton版本 兼容Spring Boot 1.3.x,也兼容Spring Boot 1.4.x
Camden版本 兼容Spring Boot 1.4.x,也兼容Spring Boot 1.5.x
Dalston版本、Edgware版本 兼容Spring Boot 1.5.x,不兼容Spring Boot 2.0.x
Finchley版本 兼容Spring Boot 2.0.x,不兼容Spring Boot 1.5.x
Greenwich版本 兼容Spring Boot 2.1.x
Hoxtonl版本 兼容Spring Boot 2.2.x
Spring BootSpring Cloud
1.5.2.RELEASE Dalston.RC1
1.5.9.RELEASE Edgware.RELEASE
2.0.2.RELEASE Finchley.BUILD-SNAPSHOT
2.0.3.RELEASE Finchley.RELEASE
2.1.0.RELEASE-2.1.14.RELEASE Greenwich.SR5
2.2.0.M4 Hoxton.SR4

 



这篇关于吐血推荐--SpringBoot与SpringCloud的版本对应说明,兼容说明的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程