Spring Boot如何无风险升级版本

Spring Boot如何无风险升级版本

Spring Boot Migrator(SBM,Spring Boot迁移器)目的是帮助程序员通过自动化的方式升级Spring Boot版本或者将非Spring Boot项目迁移到Spring Boot。

SBM基于OpenRewrite(
docs.openrewrite.org ),一个用于源代码和配置重构的通用工具。SBM目前还是Spring的实验项目,它的第一个版本发布于2022年3月。

目前SBM还处于实验阶段,目前仅支持Maven。SMB的项目地址:
github.com/spring-proje



我们在本文中将简单演示将Spring Boot 2.7.x的项目升级成Spring Boot 3.0的项目。

第一步:生成Spring Boot 2.7.x项目

访问: start.spring.io/ ,注意使用Maven构建。



我们同时为项目添加git

cd D:\migration-demo
git init
git add .
git commit -m "first commit"

第二步:下载SBM

下载最新版本的SBM:
github.com/spring-proje

第三步:启动SBM

java -jar spring-boot-migrator.jar




第四步:扫描项目

scan D:\migration-demo



从图中我们可以看出,我们有3个方案


cn-spring-cloud-config-server:将属性外部配置到Spring Cloud Config Server


boot-2.7-3.0-dependency-version-update:升级Spring Boot 2.7.x到Spring Boot 3.0。


boot-2.7-3.0-upgrade-report:创建一个将Spring Boot 2.7.x升级到Spring Boot 3.0的报告。

第五步:执行升级

apply boot-2.7-3.0-dependency-version-update



我们通过控制台可以看出它做了下面的操作:

(x) Add Spring Boot milestone repository.

(x) Add Spring Boot milestone plugin repository.

(x) Add Spring Milestone Repository and bump SpringBoot to 3.0.0-M3

(x) Set Java version to 17

(x) Migrate SAML configuration to Spring Boot 3.0 in yaml format

(x) Migrate SAML configuration to Spring Boot 3.0 in properties format

(x) Remove redundant @ConstructorBinding annotations when applicable

(x) Replace javax with new jakarta packages

(x) Add CrudRepository interface extension additionaly to PagingAndSortingRepository

(x) Migrate configuration to SpringBoot 3.0 in properties format

第六步:生成升级报告

apply boot-2.7-3.0-upgrade-report



项目下生成了一个报告文件:
SPRING_BOOT_3_UPGRADE_REPORT.html,看标题和内容看来官方还没有对这块的内容完成开发工作。



转载附加,感谢支持我的书:《从企业级开发到云原生微服务:Spring Boot实战》

头条文章地址: Spring Boot如何无风险升级版本-今日头条 (toutiao.com)

发布于 2022-10-17 09:27