吐⾎推荐--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. 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.ateBean(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.Singleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.j
ava:333) ~[spring-beans-5.3.9.jar:5.3.9]
at org.springframework.beans.factory.Bean(AbstractBeanFactory.java:213) ~[spring-beans-5.3.9.jar:5.3.9]
at t.isterBeanPostProcessors(PostProcessorRegistrationDelegate.java:270) ~[spring-context-5.3.9.jar:5.3.9]
at t.isterBeanPostProcessors(AbstractApplicationContext.java:762) ~[spring-context-5.3.9.jar:5.3.9]
at t.fresh(AbstractApplicationContext.java:567) ~[spring-context-5.3.9.jar:5.3.9]
at org.springframework.fresh(SpringApplication.java:754) ~[spring-boot-2.5.4.jar:2.5.4]
at org.springframework.freshContext(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.ApplicationEvent(BootstrapApplicationListener.java:117) [spring-cloud-context-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.cloud.ApplicationEvent(BootstrapApplicationListener.java:74) [spring-cloud-context-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at t.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) [spring-context-5.3.9.jar:5.3.9]
at t.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) [spring-context-5.3.9.jar:5.3.9]
at t.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) [spring-context-5.3.9.jar:5.3.9]
at t.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131) [spring-context-5.3.9.jar:5.3.9]
at org.t.vironmentPrepared(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.vironmentPrepared(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.t.properties.ConfigurationPropertiesBeans] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]
at org.springframework.DeclaredMethods(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 t.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.DeclaredMethods0(Native Method) ~[na:1.8.0_281]
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[na:1.8.0_281]
at java.DeclaredMethods(Class.java:1975) ~[na:1.8.0_281]
at org.springframework.DeclaredMethods(ReflectionUtils.java:463) ~[spring-core-5.3.9.jar:5.3.9]
... 37 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.t.properties.ConfigurationBeanFactoryMetadata
at java.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. 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.ateBean(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.Singleton(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.Bean(AbstractBeanFactory.java:213) ~[spring-beans-5.3.9.jar:5.3.9]
at t.isterBeanPostProcessors(PostProcessorRegistrationDelegate.java:270) ~[spring-context-5.3.9.jar:5.3.9]
at t.isterBeanPostProcessors(AbstractApplicationContext.java:762) ~[spring-context-5.3.9.jar:5.3.9]
at t.fresh(AbstractApplicationContext.java:567) ~[spring-context-5.3.9.jar:5.3.9]
at org.springframework.fresh(SpringApplication.java:754) [spring-boot-2.5.4.jar:2.5.4]
at org.springframework.freshContext(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.ApplicationEvent(BootstrapApplicationListener.java:117) ~[spring-cloud-context-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.cloud.ApplicationEvent(BootstrapApplicationListener.java:74) ~[spring-cloud-context-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at t.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) ~[spring-context-5.3.9.jar:5.3.9]
at t.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) ~[spring-context-5.3.9.jar:5.3.9]
at t.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) ~[spring-context-5.3.9.jar:5.3.9]
at t.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131) ~[spring-context-5.3.9.jar:5.3.9]
at org.t.vironmentPrepared(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.vironmentPrepared(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.t.properties.ConfigurationPropertiesBeans] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2] at org.springframework.DeclaredMethods(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 t.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]
适合新手的spring bootat 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.DeclaredMethods0(Native Method) ~[na:1.8.0_281]
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[na:1.8.0_281]
at java.DeclaredMethods(Class.java:1975) ~[na:1.8.0_281]
at org.springframework.DeclaredMethods(ReflectionUtils.java:463) ~[spring-core-5.3.9.jar:5.3.9]
... 37 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.t.properties.ConfigurationBeanFactoryMetadata
at java.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⾥⾯的依赖包,需要版本兼容才可以,⾄于如何考证,如何证实,期间⾛了多少弯路,这⾥就不赘述了,宝宝⼼⾥苦,但是宝宝不说。苦就苦我⼀⼈吧,以后⼤家遇到了知道怎么回事,避免踩这样的坑就⾏了。希望初学者,也能注意此处的问题,在引⼊依赖包的时候,要好
对应的版本。如果项⽬在初始化时正确,然后编译时报错的,基本上都是依赖包导致的问题。
注意l⾥⾯是否有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版本
根据官⽅说明我们可以知道,可以直接创建⼀个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 gener
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 determi
ne 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 都已达到⽣命周期终⽌状态,不再受⽀持。
可以看到,Spring Cloud版本是2020.0.3,是基于Supported Boot Version: 2.4.6
2.2 引⼊Spring Cloud版本
既然现在知道要使⽤哪个版本系列以及该版本系列的最新服务版本,我们可以将 Spring Cloud BOM 添加到应⽤程序中。修改l⽂件
<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 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>
三、版本对应关系
官⽅的对应关系
Release Train Boot Version
aka Ilford  2.4.x, 2.5.x (Starting with 2020.0.3)
2.2.x, 2.
3.x (Starting with SR5)
2.1.x
2.0.x
1.5.x
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版本对应关系,
可通过如下⽹址查看:
2.可以通过具体的Spring Cloud版本,然后看下该版本是基于哪个Srping Boot版本构建的
3.可以通过Spring Cloud发布的说明进⾏查看
4.在项⽬创建时,确定好⾃⼰要加载的依赖包
这种⽅式也是⽐较推荐的⽅式,在项⽬创建的时候,已经选好⾃⼰要加载的依赖包,避免不必要的⿇烦。
五、实战
⽐如我们在Spring Boot项⽬的基础上,需要加载Spring Cloud⾥⾯的依赖包spring-cloud-starter-netflix-eureka-client,我们需要注意以下⼏个地⽅:主要是l⽂件⾥⾯的这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
spring-cloud依赖spring-boot依赖
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 Cloud Spring 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 Boot Spring 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.M4Hoxton.SR4

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。