On February 28, 2018 Spring Boot enters the 2.0 era, more than 4 years ago. in November 2022 Spring Boot 3.0 will be officially released, it will be based on Spring Framework 6.0 and will require Java 17 or higher, and it will be the first Spring for Jakarta EE 9 Boot version for Jakarta EE 9. There are still six months left for developers to transition to Spring Boot 3.0, and this article will show you some ways to quickly migrate to 3.0 in the future.
Java 17
Java 17 will be the most important LTS release since Java 8 and is the result of eight years of effort by the Java community. Containing many important improvements, Java 17 is also the most powerful LTS release available. All current Spring Boot 2.x releases are well adapted to Java 17, so you don’t have to wait to start debugging the JDK upgrade and trying out some of the new features and APIs.
Upgrade to Spring Boot 2.7 as soon as possible
Spring Boot 2.7 is basically the last major release of Spring Boot 2.x. Spring Boot 2.5 has stopped OSS support and is no longer maintained, Spring Boot 2.6 will also stop being maintained after the release of Spring Boot 3.0, and the iteration is getting faster and faster. It is advisable to upgrade to 2.7 as early as possible to better migrate to 3.0, and not to jump versions, for example, not directly from 2.4 to 2.7, but try to follow steps like 2.4, 2.5, 2.6, 2.7. Too large a span is not conducive to a smooth upgrade.
Removing deprecated code
Every Spring Boot release has more or less code marked as @Deprecated
, Spring Boot 3.0 will completely remove code that is deprecated in 2.x. Of course, deprecated code from early 2.x may also be removed in the latest 2.x. Try not to use deprecated code, which is usually commented with the reason for the deprecation or an alternative API.
Configuration file mechanism changes
In Spring Boot 2.4, the loading mechanism of configuration files application.properties
and application.yaml
was changed to simplify the way external configuration is loaded and make it more logical, bringing no backward compatibility. In order to smooth the upgrade, Spring provides a configuration item to be compatible with the old mechanism.
And this mechanism will be removed in 3.0, we must use the configuration method that conforms to the new mechanism, if you exist these ways need to pay attention.
Multi-document Yaml
If you use the spacer --
in your yaml
configuration file to declare multiple documents, you need to know that declared configuration properties are now registered in the order they are declared in the document; in Spring Boot 2.3 and earlier, the order of activation is based on the configuration file. As an example.
This configuration file in Spring Boot 2.3 and earlier determines the environment to be loaded based on spring.profiles.active
. But from 2.4 onwards the later properties will override the earlier ones.
External configuration always overrides the configuration inside the jar
If your configuration file is outside the jar and the configuration file applies to a specific environment, such as application-dev.yaml
. In versions below 2.4, application.yaml
outside the jar will not overwrite the application-<profile name>.yaml
in the jar. file, from 2.4 onwards external files will always overwrite the profile inside the jar. You need to check if this is the case for you.
Activate profiles
If you used the spring.profiles
property to activate the environment configuration, you should now migrate to spring.config.activate.on-profile
.
Old usage.
New usage.
This is a real toss-up. spring.profiles.active
can still be used to activate specific environments, e.g. command line.
|
|
You can also use spring.profiles.active
in application.properties
or application.yaml
, but as of 2.4 spring.profiles.active
cannot be used in a specific environment, i.e. application-<profile>.yaml
, nor can it be used in multiple documents separated by ---
. In a nutshell, you can no longer use spring.profiles.active
to merge a profile that contains the spring.config.activate.on-profile
property.
By the same mechanism, the spring.profiles.include
property can only be used in non-specific configuration files, and the following configuration is invalid.
For more points, please refer to the official documentation: Spring Boot Config Data Migration Guide.
A higher performance path parsing approach
Starting with Spring Boot 2.6, path parsing uses PathPatternParser
by default, replacing the previous Ant-style matching AntPathMatcher
. After the upgrade, people using Swagger started up with the following exception.
|
|
This was resolved with the configuration item spring.mvc.pathmatch.matching-strategy=ant_path_matcher
. While AntPathMatcher
will continue to work in Spring Boot 3.0, PathPatternParser
is the official recommendation because of its higher performance, and I’ll have a feature on PathPatternParser
later on.
Compatibility issues
The first issue is Jakarta EE 9 compatibility, make sure your third party dependency libraries and your code are compatible with Jakarta EE 9. Also check if any of the third party dependency jars being used by the Spring Framework are planned to be compatible with Spring 6.
Try to learn Spring 6
Spring 6 and Spring Boot 3 have been released with multiple milestones, so take some time in your free time to try them out, experience the new features and changes, and evaluate the difficulty of upgrading your application.