Skip to content

Commit 08aaafe

Browse files
committed
Add a page to upgrade to Spring Boot 4
1 parent ebcb1fc commit 08aaafe

File tree

1 file changed

+155
-0
lines changed

1 file changed

+155
-0
lines changed
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
---
2+
sidebar_position: 7
3+
---
4+
import Tabs from '@theme/Tabs';
5+
import TabItem from '@theme/TabItem';
6+
7+
# Upgrade to Spring Boot 4.0
8+
9+
To upgrade your project from Spring Boot 3.x to Spring Boot 4.0, you can [use the OpenRewrite recipe](https://docs.openrewrite.org/recipes/java/spring/boot4/upgradespringboot_4_0-community-edition) `org.openrewrite.java.spring.boot4.UpgradeSpringBoot_4_0` from `rewrite-spring`.
10+
11+
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.
12+
13+
You can run the migration recipe using one of the following methods.
14+
15+
<Tabs groupId="projectType">
16+
<TabItem value="moderne-cli" label="Moderne CLI">
17+
18+
The Moderne CLI allows you to run OpenRewrite recipes on your project without needing to modify your build files,
19+
against serialized Lossless Semantic Tree (LST) of your project for a considerable performance boost & across projects.
20+
21+
You will need to have configured the [Moderne CLI](https://docs.moderne.io/user-documentation/moderne-cli/getting-started/cli-intro) on your machine before you can run the following command.
22+
23+
1. If project serialized Lossless Semantic Tree is not yet available locally, then build the LST.
24+
This is only needed the first time, or after extensive changes:
25+
```bash title="shell"
26+
mod build ~/workspace/
27+
```
28+
29+
2. If the recipe is not available locally yet, then you can install it once using:
30+
```shell title="shell"
31+
mod config recipes jar install org.openrewrite.recipe:rewrite-spring:LATEST
32+
```
33+
34+
3. Run the recipe.
35+
```shell title="shell"
36+
mod run ~/workspace/ --recipe org.openrewrite.java.spring.boot4.UpgradeSpringBoot_4_0
37+
```
38+
39+
</TabItem>
40+
<TabItem value="maven-command-line" label="Maven Command Line">
41+
42+
You will need to have [Maven](https://maven.apache.org/download.cgi) installed on your machine before you can run the following command.
43+
44+
```shell title="shell"
45+
mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-spring:RELEASE -Drewrite.activeRecipes=org.openrewrite.java.spring.boot4.UpgradeSpringBoot_4_0 -Drewrite.exportDatatables=true
46+
```
47+
48+
</TabItem>
49+
<TabItem value="maven" label="Maven POM">
50+
51+
You may add the plugin to your `pom.xml` file, so that it is available for all developers and CI/CD pipelines.
52+
53+
1. Add the following to your `pom.xml` file:
54+
55+
```xml title="pom.xml"
56+
<project>
57+
<build>
58+
<plugins>
59+
<plugin>
60+
<groupId>org.openrewrite.maven</groupId>
61+
<artifactId>rewrite-maven-plugin</artifactId>
62+
<version>LATEST</version>
63+
<configuration>
64+
<exportDatatables>true</exportDatatables>
65+
<activeRecipes>
66+
<recipe>org.openrewrite.java.spring.boot4.UpgradeSpringBoot_4_0</recipe>
67+
</activeRecipes>
68+
</configuration>
69+
<dependencies>
70+
<dependency>
71+
<groupId>org.openrewrite.recipe</groupId>
72+
<artifactId>rewrite-spring</artifactId>
73+
<version>LATEST</version>
74+
</dependency>
75+
</dependencies>
76+
</plugin>
77+
</plugins>
78+
</build>
79+
</project>
80+
```
81+
82+
2. Run run the recipe.
83+
```shell title="shell"
84+
mvn rewrite:run
85+
```
86+
87+
</TabItem>
88+
<TabItem value="gradle-init-script" label="Gradle init script">
89+
90+
Gradle init scripts are a good way to try out a recipe without modifying your `build.gradle` file.
91+
92+
1. Create a file named `init.gradle` in the root of your project.
93+
94+
```groovy title="init.gradle"
95+
initscript {
96+
repositories {
97+
maven { url "https://plugins.gradle.org/m2" }
98+
}
99+
dependencies { classpath("org.openrewrite:plugin:latest.release") }
100+
}
101+
rootProject {
102+
plugins.apply(org.openrewrite.gradle.RewritePlugin)
103+
dependencies {
104+
rewrite("org.openrewrite.recipe:rewrite-spring:latest.release")
105+
}
106+
rewrite {
107+
activeRecipe("org.openrewrite.java.spring.boot4.UpgradeSpringBoot_4_0")
108+
setExportDatatables(true)
109+
}
110+
afterEvaluate {
111+
if (repositories.isEmpty()) {
112+
repositories {
113+
mavenCentral()
114+
}
115+
}
116+
}
117+
}
118+
```
119+
120+
2. Run the recipe.
121+
122+
```shell title="shell"
123+
gradle --init-script init.gradle rewriteRun
124+
```
125+
126+
</TabItem>
127+
<TabItem value="gradle" label="Gradle">
128+
129+
You can add the plugin to your `build.gradle` file, so that it is available for all developers and CI/CD pipelines.
130+
131+
1. Add the following to your `build.gradle` file:
132+
133+
```groovy title="build.gradle"
134+
plugins {
135+
id("org.openrewrite.rewrite") version("latest.release")
136+
}
137+
138+
rewrite {
139+
activeRecipe("org.openrewrite.java.spring.boot4.UpgradeSpringBoot_4_0")
140+
setExportDatatables(true)
141+
}
142+
143+
repositories {
144+
mavenCentral()
145+
}
146+
147+
dependencies {
148+
rewrite("org.openrewrite.recipe:rewrite-spring:latest.release")
149+
}
150+
```
151+
152+
2. Run `gradle rewriteRun` to run the recipe.
153+
154+
</TabItem>
155+
</Tabs>

0 commit comments

Comments
 (0)