Spring Boot 3.0 is a new major release that offers new features and improvements. However, it requires Java 17 as a minimum version and comes with numerous compatibility issues if you intend to upgrade.
I. Pros and Cons
You need to analyze the pros and cons of our migration. In my experience, there are some points you should review:
1.1. Pros
Java 17 Baseline
You’ll need to upgrade to JDK 17 before you can develop Spring Boot 3.0 applications. This means you can take advantage of the latest features and performance improvements that Java 17 offers.
GraalVM Native Image Support
GraalVM Native Images provide a new way to deploy and run Java applications. It provides various advantages, like an instant startup and reduced memory consumption (pain points of Spring Boot apps).
Improved observability with Micrometer and Micrometer Tracing
You can check more details before migrating to Spring Boot 3.0. It minimizes compatibility issues as much as possible.
Review Dependencies
You can review your dependencies and
This project includes the implementation of common backend features, designed to assist both myself and other Spring Boot developers in coding more efficiently. For further details, you can read more useful, please give it a star ⭐️!
3.2. Migration Steps
3.2.1. Configuration Properties Migration
Let's add the migrator by adding the following to your Maven pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-properties-migrator</artifactId>
<scope>runtime</scope>
</dependency>
This will analyze your application’s environment and print diagnostics at startup console logs. Then you can based on that update your properties accordingly.
3.2.2. Update Dependencies
- We start with the parent pom spring-boot-starter-parent and Java version
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<java.version>17</java.version>
</properties>
Tips: We shouldn't specify the version of Spring Data JPA, Spring Web, Spring Data Redis,... because their compatible versions are already declared in the parent POM.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
- If you are working with MySQL, let's replace your mysql-connector-java by:
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.1.0</version>
</dependency>
- If you are using logback for logging, let's update it to v1.4.11
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.4.11</version>
</dependency>
- If you are using Openfeign for integrations, let's update it to v4.x
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>4.0.4</version>
</dependency>
- If you are using Spring JDBC, let's update it to v6.x
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>6.0.12</version>
</dependency>
- If you are using Jackson for data binding, let's update it to v2.15.x
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.15.3</version>
</dependency>
<!-- support Java 8 Date/time Serialize/Deserialize -->
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.15.3</version>
</dependency>
- If you are using Redisson as a Redis client, let's update it to v3.24.x
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson-spring-boot-starter</artifactId>
<version>3.24.3</version>
</dependency>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson-spring-data-31</artifactId>
<version>3.24.3</version>
</dependency>
- You should use the default spring-boot-starter-test for unit testing. However, If you are customizing mockito-core, let's update it to v5.3.x
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
- If you are using jjwt for authentication, let's update it to 0.12.x
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.12.3</version>
</dependency>
- If you are using Springdoc for API documentation, let's replace your springdoc-openapi-ui by:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.2.0</version>
</dependency>
- If you are using spring-kafka as your Kafka client, let's update it to v3.0.x
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
<version>3.0.10</version>
</dependency>
3.2.3. Rebuild and change the code
- After updating your dependencies, let's rebuild your code first and check for any issues
mvn clean package
- Spring Boot 3.0 has migrated from Java EE to Jakarta EE APIs for all dependencies. So you should face the javax issue in your first build:
- If the Spring migrator is working, you can see a WARNING log in the startup console:
useful, please give it a star ⭐️!
Henry Pham.
SOCIAL SHARE CARD GENERATOR