Skip to main content

Upgrade to Spring Boot 4.0

To upgrade your project from Spring Boot 3.x to Spring Boot 4.0, you can use the OpenRewrite recipe org.openrewrite.java.spring.boot4.UpgradeSpringBoot_4_0 from rewrite-spring.

This recipe will automatically update your Spring Boot dependencies to version 4.0 and apply the necessary code changes to ensure compatibility, including updating deprecated APIs, migrating configuration properties, and adapting to framework changes introduced in Spring Boot 4.0.

You can run the migration recipe using one of the following methods.

The Moderne CLI allows you to run OpenRewrite recipes on your project without needing to modify your build files, against serialized Lossless Semantic Tree (LST) of your project for a considerable performance boost & across projects.

You will need to have configured the Moderne CLI on your machine before you can run the following command.

  1. If project serialized Lossless Semantic Tree is not yet available locally, then build the LST. This is only needed the first time, or after extensive changes:
shell
mod build ~/workspace/
  1. If the recipe is not available locally yet, then you can install it once using:
shell
mod config recipes jar install org.openrewrite.recipe:rewrite-spring:LATEST
  1. Run the recipe.
shell
mod run ~/workspace/ --recipe org.openrewrite.java.spring.boot4.UpgradeSpringBoot_4_0

Next steps

Customize the Spring Boot 4.0 upgrade recipe to fit your project's specific needs by extending it with additional transformations or configurations as required. This can be to bring along internal libraries or frameworks as you upgrade, or to expand the recipes beyond what is covered out of the box. As always: if you develop any recipes useful to others, consider contributing back to the community!