当前位置:   article > 正文

SpringBoot与SpringCloud的版本对应说明,兼容说明

SpringBoot与SpringCloud的版本对应说明,兼容说明

本文为joshua317原创文章,转载请注明:转载自joshua317博客 SpringBoot与SpringCloud的版本对应说明,兼容说明 - joshua317的博客

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

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

由于最近刚开始接触SpringBoot,当时创建项目的时候,没有直接添加依赖,所以后来在pom.xml里面加载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依赖包已经下载下来

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

  1. 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]
  2. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:579) ~[spring-beans-5.3.9.jar:5.3.9]
  3. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[spring-beans-5.3.9.jar:5.3.9]
  4. at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.9.jar:5.3.9]
  5. at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.9.jar:5.3.9]
  6. at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.9.jar:5.3.9]
  7. at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:213) ~[spring-beans-5.3.9.jar:5.3.9]
  8. at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:270) ~[spring-context-5.3.9.jar:5.3.9]
  9. at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:762) ~[spring-context-5.3.9.jar:5.3.9]
  10. at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:567) ~[spring-context-5.3.9.jar:5.3.9]
  11. at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-2.5.4.jar:2.5.4]
  12. at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) ~[spring-boot-2.5.4.jar:2.5.4]
  13. at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) ~[spring-boot-2.5.4.jar:2.5.4]
  14. at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:143) [spring-boot-2.5.4.jar:2.5.4]
  15. at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:212) [spring-cloud-context-2.2.6.RELEASE.jar:2.2.6.RELEASE]
  16. at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:117) [spring-cloud-context-2.2.6.RELEASE.jar:2.2.6.RELEASE]
  17. at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:74) [spring-cloud-context-2.2.6.RELEASE.jar:2.2.6.RELEASE]
  18. at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) [spring-context-5.3.9.jar:5.3.9]
  19. at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) [spring-context-5.3.9.jar:5.3.9]
  20. at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) [spring-context-5.3.9.jar:5.3.9]
  21. at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131) [spring-context-5.3.9.jar:5.3.9]
  22. at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:82) [spring-boot-2.5.4.jar:2.5.4]
  23. at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:63) [spring-boot-2.5.4.jar:2.5.4]
  24. at java.util.ArrayList.forEach(ArrayList.java:1259) ~[na:1.8.0_281]
  25. at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:117) [spring-boot-2.5.4.jar:2.5.4]
  26. at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:111) [spring-boot-2.5.4.jar:2.5.4]
  27. at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:62) [spring-boot-2.5.4.jar:2.5.4]
  28. at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:374) ~[spring-boot-2.5.4.jar:2.5.4]
  29. at org.springframework.boot.SpringApplication.run(SpringApplication.java:332) ~[spring-boot-2.5.4.jar:2.5.4]
  30. at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) ~[spring-boot-2.5.4.jar:2.5.4]
  31. at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332) ~[spring-boot-2.5.4.jar:2.5.4]
  32. at com.joshua317.blog.BlogApplication.main(BlogApplication.java:12) ~[classes/:na]
  33. Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.context.properties.ConfigurationPropertiesBeans] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]
  34. at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:481) ~[spring-core-5.3.9.jar:5.3.9]
  35. at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321) ~[spring-core-5.3.9.jar:5.3.9]
  36. at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.buildLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:232) ~[spring-beans-5.3.9.jar:5.3.9]
  37. at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.findLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:210) ~[spring-beans-5.3.9.jar:5.3.9]
  38. at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(InitDestroyAnnotationBeanPostProcessor.java:149) ~[spring-beans-5.3.9.jar:5.3.9]
  39. at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(CommonAnnotationBeanPostProcessor.java:294) ~[spring-context-5.3.9.jar:5.3.9]
  40. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:1098) ~[spring-beans-5.3.9.jar:5.3.9]
  41. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:576) ~[spring-beans-5.3.9.jar:5.3.9]
  42. ... 30 common frames omitted
  43. Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
  44. at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_281]
  45. at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[na:1.8.0_281]
  46. at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[na:1.8.0_281]
  47. at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463) ~[spring-core-5.3.9.jar:5.3.9]
  48. ... 37 common frames omitted
  49. Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata
  50. at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[na:1.8.0_281]
  51. at java.lang.ClassLoader.loadClass(ClassLoader.java:418) ~[na:1.8.0_281]
  52. at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355) ~[na:1.8.0_281]
  53. at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ~[na:1.8.0_281]
  54. ... 41 common frames omitted
  55. 2021-09-16 10:58:56.852 ERROR 15524 --- [ main] o.s.boot.SpringApplication : Application run failed
  56. 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]
  57. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:579) ~[spring-beans-5.3.9.jar:5.3.9]
  58. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[spring-beans-5.3.9.jar:5.3.9]
  59. at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.9.jar:5.3.9]
  60. at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.9.jar:5.3.9]
  61. at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.9.jar:5.3.9]
  62. at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:213) ~[spring-beans-5.3.9.jar:5.3.9]
  63. at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:270) ~[spring-context-5.3.9.jar:5.3.9]
  64. at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:762) ~[spring-context-5.3.9.jar:5.3.9]
  65. at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:567) ~[spring-context-5.3.9.jar:5.3.9]
  66. at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) [spring-boot-2.5.4.jar:2.5.4]
  67. at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) [spring-boot-2.5.4.jar:2.5.4]
  68. at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) [spring-boot-2.5.4.jar:2.5.4]
  69. at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:143) ~[spring-boot-2.5.4.jar:2.5.4]
  70. at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:212) ~[spring-cloud-context-2.2.6.RELEASE.jar:2.2.6.RELEASE]
  71. at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:117) ~[spring-cloud-context-2.2.6.RELEASE.jar:2.2.6.RELEASE]
  72. at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:74) ~[spring-cloud-context-2.2.6.RELEASE.jar:2.2.6.RELEASE]
  73. at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) ~[spring-context-5.3.9.jar:5.3.9]
  74. at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) ~[spring-context-5.3.9.jar:5.3.9]
  75. at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) ~[spring-context-5.3.9.jar:5.3.9]
  76. at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131) ~[spring-context-5.3.9.jar:5.3.9]
  77. at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:82) ~[spring-boot-2.5.4.jar:2.5.4]
  78. at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:63) ~[spring-boot-2.5.4.jar:2.5.4]
  79. at java.util.ArrayList.forEach(ArrayList.java:1259) ~[na:1.8.0_281]
  80. at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:117) ~[spring-boot-2.5.4.jar:2.5.4]
  81. at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:111) ~[spring-boot-2.5.4.jar:2.5.4]
  82. at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:62) ~[spring-boot-2.5.4.jar:2.5.4]
  83. at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:374) [spring-boot-2.5.4.jar:2.5.4]
  84. at org.springframework.boot.SpringApplication.run(SpringApplication.java:332) [spring-boot-2.5.4.jar:2.5.4]
  85. at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) [spring-boot-2.5.4.jar:2.5.4]
  86. at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332) [spring-boot-2.5.4.jar:2.5.4]
  87. at com.joshua317.blog.BlogApplication.main(BlogApplication.java:12) [classes/:na]
  88. Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.context.properties.ConfigurationPropertiesBeans] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]
  89. at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:481) ~[spring-core-5.3.9.jar:5.3.9]
  90. at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321) ~[spring-core-5.3.9.jar:5.3.9]
  91. at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.buildLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:232) ~[spring-beans-5.3.9.jar:5.3.9]
  92. at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.findLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:210) ~[spring-beans-5.3.9.jar:5.3.9]
  93. at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(InitDestroyAnnotationBeanPostProcessor.java:149) ~[spring-beans-5.3.9.jar:5.3.9]
  94. at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(CommonAnnotationBeanPostProcessor.java:294) ~[spring-context-5.3.9.jar:5.3.9]
  95. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:1098) ~[spring-beans-5.3.9.jar:5.3.9]
  96. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:576) ~[spring-beans-5.3.9.jar:5.3.9]
  97. ... 30 common frames omitted
  98. Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
  99. at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_281]
  100. at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[na:1.8.0_281]
  101. at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[na:1.8.0_281]
  102. at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463) ~[spring-core-5.3.9.jar:5.3.9]
  103. ... 37 common frames omitted
  104. Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata
  105. at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[na:1.8.0_281]
  106. at java.lang.ClassLoader.loadClass(ClassLoader.java:418) ~[na:1.8.0_281]
  107. at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355) ~[na:1.8.0_281]
  108. at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ~[na:1.8.0_281]
  109. ... 41 common frames omitted
  110. 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,这样最终保证你所需要的依赖包能够争取无误的加载下来。如下面的代码示例:

  1. <properties>
  2. <java.version>1.8</java.version>
  3. <spring-cloud.version>2020.0.3</spring-cloud.version>
  4. </properties>
  5. <dependencyManagement>
  6. <dependencies>
  7. <dependency>
  8. <groupId>org.springframework.cloud</groupId>
  9. <artifactId>spring-cloud-dependencies</artifactId>
  10. <version>${spring-cloud.version}</version>
  11. <type>pom</type>
  12. <scope>import</scope>
  13. </dependency>
  14. </dependencies>
  15. </dependencyManagement>
  16. <dependencies>
  17. <dependency>
  18. <groupId>org.springframework.boot</groupId>
  19. <artifactId>spring-boot-starter-web</artifactId>
  20. </dependency>
  21. <dependency>
  22. <groupId>org.springframework.cloud</groupId>
  23. <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
  24. </dependency>
  25. <dependency>
  26. <groupId>org.springframework.boot</groupId>
  27. <artifactId>spring-boot-starter-test</artifactId>
  28. <scope>test</scope>
  29. </dependency>
  30. </dependencies>

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

二、如何查看版本对应

2.1 查看Spring Cloud版本

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

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

  1. Getting Started
  2. Generating A New Spring Cloud Project
  3. 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.
  4. Adding Spring Cloud To An Existing Spring Boot Application
  5. 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.
  6. The table below outlines which version of Spring Cloud maps to which version of Spring Boot.
  7. 入门
  8. 生成一个新的 Spring Cloud 项目
  9. 最简单的入门方法是访问start.spring.io,选择您的 Spring Boot 版本和您要使用的 Spring Cloud 项目。这将在您生成项目时将相应的 Spring Cloud BOM 版本添加到您的 Maven/Gradle 文件中。
  10. 将 Spring Cloud 添加到现有的 Spring Boot 应用程序
  11. 如果您想要将 Spring Cloud 添加到该应用程序的现有 Spring Boot 应用程序,第一步是确定您应该使用的 Spring Cloud 版本。您在应用中使用的版本取决于您使用的 Spring Boot 版本。
  12. 下表概述了 Spring Cloud 的哪个版本映射到 Spring Boot 的哪个版本。

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

  1. Spring Cloud Dalston, Edgware, Finchley, and Greenwich have all reached end of life status and are no longer supported.
  2. 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文件

  1. <properties>
  2. <spring.cloud-version>Hoxton.SR8</spring.cloud-version>
  3. </properties>
  4. <dependencyManagement>
  5. <dependencies>
  6. <dependency>
  7. <groupId>org.springframework.cloud</groupId>
  8. <artifactId>spring-cloud-dependencies</artifactId>
  9. <version>${spring.cloud-version}</version>
  10. <type>pom</type>
  11. <scope>import</scope>
  12. </dependency>
  13. </dependencies>
  14. </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 客户端添加到您的应用程序中。

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.springframework.cloud</groupId>
  4. <artifactId>spring-cloud-starter-config</artifactId>
  5. </dependency>
  6. <dependency>
  7. <groupId>org.springframework.cloud</groupId>
  8. <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
  9. </dependency>
  10. ...
  11. </dependencies>

三、版本对应关系

官方的对应关系

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

Release TrainBoot Version
2020.0.x aka Ilford2.4.x, 2.5.x (Starting with 2020.0.3)
Hoxton2.2.x, 2.3.x (Starting with SR5)
Greenwich2.1.x
Finchley2.0.x
Edgware1.5.x
Dalston1.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版本构建的

Spring Cloud

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 版本

  1. <parent>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-parent</artifactId>
  4. <version>2.5.4</version>
  5. <relativePath/> <!-- lookup parent from repository -->
  6. </parent>

(2)Spring Cloud版本

  1. <properties>
  2. <java.version>1.8</java.version>
  3. <spring-cloud.version>2020.0.3</spring-cloud.version>
  4. </properties>

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

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

  1. <dependencyManagement>
  2. <dependencies>
  3. <dependency>
  4. <groupId>org.springframework.cloud</groupId>
  5. <artifactId>spring-cloud-dependencies</artifactId>
  6. <version>${spring-cloud.version}</version>
  7. <type>pom</type>
  8. <scope>import</scope>
  9. </dependency>
  10. </dependencies>
  11. </dependencyManagement>

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

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.springframework.boot</groupId>
  4. <artifactId>spring-boot-starter-web</artifactId>
  5. </dependency>
  6. <dependency>
  7. <groupId>org.springframework.cloud</groupId>
  8. <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
  9. </dependency>
  10. <dependency>
  11. <groupId>org.springframework.boot</groupId>
  12. <artifactId>spring-boot-starter-test</artifactId>
  13. <scope>test</scope>
  14. </dependency>
  15. </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.RELEASEDalston.RC1
1.5.9.RELEASEEdgware.RELEASE
2.0.2.RELEASEFinchley.BUILD-SNAPSHOT
2.0.3.RELEASEFinchley.RELEASE
2.1.0.RELEASE-2.1.14.RELEASEGreenwich.SR5
2.2.0.M4Hoxton.SR4

本文为joshua317原创文章,转载请注明:转载自joshua317博客 SpringBoot与SpringCloud的版本对应说明,兼容说明 - joshua317的博客

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号