The recent release of VMware’s Spring Boot 3, along with the new version of Spring Framework 6, brings a series of significant and disruptive improvements compared to their previous versions, bringing us closer to a Cloud Native world. In this article, we will explore What’s New in Spring Boot 3 and Spring Framework 6.
New Features and Improvements in Spring 6
After 5 years with Spring Framework 5, the new version brings significant changes, so let’s see What’s New in Spring Boot 3 and Spring Framework 6:
- Java 17: Although previous versions of Spring Boot already allowed the use of Java 17, the new version of Spring Boot and Framework will require the use of Java 17.
- Replacing Java EE with Jakarta EE: The minimum supported version is Jakarta EE 9, which breaks compatibility with previous versions. The package name migrates from javax.* to jakarta.*. The use of Jakarta EE 10 will make Spring Framework 6 compatible with the latest versions of servers like Tomcat 10.1, Jetty 11, and Undertow 2.3.
- Simplified Queries with Spring Data.
- More manageable and understandable HTTP errors with RFC 7807.
- Native Compilation: Undoubtedly one of the most desired improvements, this enhancement brings Spring closer to what Quarkus currently offers. This improvement could already be used by adding the spring-native module.
- Observability: As the goal is to move towards a more cloud-native environment, observability based on metric logging is added with Micrometer and providers like OpenZipkin and OpenTelemetry.
- JPMS: Although not in the initial version, the goal is to have it for future releases, providing stricter access to application and library code.
- Spring 6 will also incorporate features from the Loom project (Virtual Threads).
- Update to Kotlin 1.7, Hibernate ORM 6.1, Jackson 2.14, and R2DBC 1.0 for reactive database usage.
- New version of Flyway.
New Features and Changes in Spring Boot 3
As expected, the changes in Spring 6 are applied to Spring Boot 3.
Furthermore, all deprecated features and functionalities have been removed.
How to Update and Migrate an Application to Spring 6 and Spring Boot 3?
Spring Boot provides a tool called Spring Boot Migrator to simplify the migration process. This tool can assist in migrating from version 2.7 to 3.0. However, it is currently an experimental project (in case anything goes wrong).
Here are the changes to consider for migration:
Migrate to Java 17
The first step in our application would be to migrate to Java 17. Some modifications may be required in the pom.xml file.
Recommended to Update to the Latest Versions of Spring 5 and Spring Boot 2
Throughout the different releases of Spring 5 and Spring Boot 2, some classes have been deprecated. It is ideal to have replaced all those deprecated classes before moving to version 3 of Spring Boot since they will no longer exist. Therefore, updating to the latest version of Spring 5 and Spring Boot 2 will help mitigate any issues with deprecated classes.
Change from Javax to Jakarta
Once the version is changed to Spring Boot 3, it will be necessary to change all packages from javax.* to jakarta.*
Update HttpClient
If you are still using RestTemplate (although it is not very common anymore), it will be necessary to update to HttpClient 5.
Changes in HttpMethod
The HttpMethod class was previously an enum class. However, in the new version of Spring Boot 3, it will no longer be displayed as an enum. Therefore, the code will need to be adapted accordingly.
Changes in Log4j2 Version
When manually adding the Log4j2 version, it will be necessary to determine the latest version to be used.
Log Date Formatting
The date format in Logback and Log4j2 has changed to follow ISO-8601, using the new format yyyy-MM-dd ‘T’ HH:mm:ss.SSSXXX. If you don’t like this format and want to keep the previous one, it can be done using logging.pattern.dateformat or by using the environment variable LOG_DATEFORMAT_PATTERN.
Usage of spring.factories
The usage of spring.factories was used for creating automated configurations. However, in version 3, autoconfigurations can only be done through import files.
YamlJsonParser
If YamlJsonParser is being used in any project, it will be necessary to switch to another JsonParser.
Property server.max-http-header-size changes
The property server.max-http-size is replaced by server.max-http-request-header-size.
Prefix spring.data
All projects that use Spring Data now require the prefix spring.data in their configurations. Therefore, configurations in the application.yaml files should now include the data prefix. For example, spring.elasticsearch should now be spring.data.elasticsearch.
Changes in MongoDB and Elasticsearch
The automatic configuration of Flapdoodle embedded MongoDB and the REST client for Elasticsearch uses a new implementation.
Conclusion about What’s New in Spring Boot 3 and Spring Framework 6
Spring Framework 6, along with Spring Boot 3, brings significant changes. From my point of view, perhaps the most important and anticipated one is the use of native images, which although could be used by importing the module for some time, is a significant improvement in approaching the cloud-native world.
If you need more information, you can leave us a comment or send an email to refactorizando.web@gmail.com You can also contact us through our social media channels on Facebook or twitter and we will be happy to assist you!!