SpringBoot和SpringCloud版本对应

随着SpringBoot 3.0预计在2022年11月发布,它将基于Spring Framework 6.0和Java 17。本文介绍了SpringBoot 3.0的主要变化,包括移除弃用API,提高最低Java版本要求至17,采用JakartaEE 9规范,以及对第三方库的支持。此外,还详细讨论了配置文件加载机制的变更,如spring.profiles.active的使用限制。开发者需要提前了解并计划迁移策略,以应对即将到来的不兼容性问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

官网版本对应地址:https://start.spring.io/actuator/info

SpringCloud版本SpringBoot版本
2022.0.0-M2Spring Boot >=3.0.0-M2 and < 3.1.0-M1
2022.0.0-M1Spring Boot >=3.0.0-M1 and < 3.0.0-M2
2021.0.3Spring Boot >=2.6.1 and < 3.0.0-M1
2021.0.0-RC1Spring Boot >=2.6.0-RC1 and <2.6.1
2021.0.0-M3Spring Boot >=2.6.0-M3 and <2.6.0-RC1
2021.0.0-M1Spring Boot >=2.6.0-M1 and <2.6.0-M3
2020.0.5Spring Boot >=2.4.0.M1 and <2.6.0-M1
Hoxton.SR12Spring Boot >=2.2.0.RELEASE and <2.4.0.M1
Hoxton.BUILD-SNAPSHOTSpring Boot >=2.2.0.BUILD-SNAPSHOT
Hoxton.M2Spring Boot >=2.2.0.M4 and <=2.2.0.M5
Greenwich.BUILD-SNAPSHOSpring Boot >=2.1.9.BUILD-SNAPSHOT and <2.2.0.M4
Greenwich.SR2Spring Boot >=2.1.0.RELEASE and <2.1.9.BUILD-SNAPSHOT
Greenwich.M1Spring Boot >=2.1.0.M3 and <2.1.0.RELEASE
Finchley.BUILD-SNAPSHOTSpring Boot >=2.0.999.BUILD-SNAPSHOT and <2.1.0.M3
Finchley.SR4Spring Boot >=2.0.3.RELEASE and <2.0.999.BUILD-SNAPSHOT
Finchley.RC2Spring Boot >=2.0.2.RELEASE and <2.0.3.RELEASE
Finchley.RC1Spring Boot >=2.0.1.RELEASE and <2.0.2.RELEASE
Finchley.M9Spring Boot >=2.0.0.RELEASE and <=2.0.0.RELEASE
Finchley.M7Spring Boot >=2.0.0.RC2 and <=2.0.0.RC2
Finchley.M6Spring Boot >=2.0.0.RC1 and <=2.0.0.RC1
Finchley.M5Spring Boot >=2.0.0.M7 and <=2.0.0.M7
Finchley.M4Spring Boot >=2.0.0.M6 and <=2.0.0.M6
Finchley.M3Spring Boot >=2.0.0.M5 and <=2.0.0.M5
Finchley.M2Spring Boot >=2.0.0.M3 and <2.0.0.M5

☆博主在使用的版本★:

  1. Jdk: 1.8
  2. Spring Boot : 2.3.9.RELEASE
  3. Spring Cloud: Hoxton SR12
  4. Spring Cloud AliBaBa: 2.2.5.RELEASE

三、Spring boot最新追踪
正式版本即将在2022 年11月Spring Boot 3.0正式发布,它将基于Spring Framework 6.0,并且需要 Java 17 或更高版本,同时它也将是Jakarta EE 9的第一个Spring Boot版本。留给开发者的时间不多了,那么我们如何过渡到Spring Boot 3.0,今天告诉大家一些方法,以便于将来快速迁移到3.0。快来一睹为快。

Spring Boot 3.0M1 一些已知的变更
为了跟上形势,一些已知的变化更需要大家知道。

移除Spring Boot 2.x的弃用API

Spring Boot 2.x 中弃用的类、方法和属性会在3.0版本中删除。

最低Java要求

  • 从Spring Boot 3.0开始:
    • Java 17是最低版本,Java 8不再被兼容。
    • 到正式版发行的时候Java 19也应该发行了。

Jakarta EE 9

Spring Boot 依赖于 Jakarta EE 规范,3.0 已经升级到 Jakarta EE 9 版本。因此Spring Boot 3.0 会使用 Servlet 5.0规范和JPA 3.0规范。相关的三方依赖如果不支持这些规范,将减少或者移除这些依赖。所以相关的三方依赖请尽快根据 Jakarta EE 9 进行版本迭代。基于这个原因,目前不支持Jakarta EE 9的类库将被移除,包含了一些知名三方类库,例如EhCache3、Jersey、JOOQ、Thymeleaf等等,直到这些类库适配 Jakarta EE 9。

(永久)移除支持

以下三个中间件单独被列了出来,感觉像是永久不再支持了。

Apache ActiveMQ

Atomikos

EhCache 2

依赖升级

Spring Boot 3.0的一些Spring依赖项目也都升级到了新的里程碑版本,其中包含了Spring Security 6.0-M1。Jakarta EE相关的模块也升级到了Jakarta EE 9。

更多特性参见Spring Boot3.0M1更新日志

Spring Boot 3.0迁移指南
​配置文件机制的更改
在Spring Boot 2.4中,配置文件 application.properties 和 application.yaml 的加载机制被改变,目的是为了简化外部配置的加载方式,使之更加合理,带来的是不向下兼容。为了平滑升级,Spring 提供了一个配置项来兼容旧机制:

例如,你可以有一个src/main/resources/application。 属性如下:

spring.config.use-legacy-processing=true
多文档Yaml
如果你在yaml配置文件中使用了间隔符—来声明多文档的话,你得知道现在按文档声明的顺序来注册声明的配置属性;而在 Spring Boot 2.3 及更早版本中,基于配置文件激活顺序。举个例子:

spring:
  profiles: 
    active: test
  application:
    name: test-service
server:

spring:
  profiles:
    active: uat
  application:
    name: test-service
server:
  port: 8080

这个配置文件在Spring Boot 2.3以前的版本中会根据spring.profiles.active来决定加载的环境。但是从2.4开始后面的属性会覆盖前面的属性。

外部配置总是覆盖jar内的配置
如果你的配置文件在jar之外,并且该配置文件适用于特定的环境,例如application-dev.yaml。2.4以下的版本中,在jar外面的application.yaml不会覆盖jar中的application-<profile名称>.yaml文件,从2.4开始外部文件将总是覆盖jar内的配置文件。你需要检查你是否存在这种情况。

激活配置文件
如果您使用spring.profiles属性来激活环境配置,那么现在就应该迁移到spring.config.activate.on-profile

旧玩法:

spring:
  profiles: "dev"
secret: "dev-password"

新玩法:

spring:
  config:
    activate:
      on-profile: "dev"
secret: "dev-password"

这真是折腾人啊。spring.profiles.active仍然可以用来激活特定的环境,例如命令行:

$ java -jar myapp.jar --spring.profiles.active=prod

你也可以在 application.properties 或 application.yaml 中使用spring.profiles.active,从2.4开始spring.profiles.active不能在特定环境中使用,也就是说application-.yaml中不能使用,—间隔的多文档中也不能使用它。一句话,你不能再通过spring.profiles.active来合并一个包含了spring.config.activate.on-profile属性的配置文件。

同样的机制, spring.profiles.include属性只能在非特定配置文件中使用,下面的配置是无效的:

无效配置

spring:
  config:
    activate:
      on-profile: "prod"
  profiles:
    include: "metrics"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

杨校

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值