upgrade background
springboot2.3.7 is too old, and it is no longer officially supported. (Personally, to be honest, it’s actually okay, but springboot has been a bit convulsive recently, too fast. It’s really not that the national jun is not strong, but the communist jun is too powerful!)
Check out the current version support: Spring Boot Level up your Java code and explore what Spring can do for you. https://spring.io/projects/spring-boot#support
The 2.3.X version was gg last year.
For the sake of everything, it must be upgraded.
Since you want to upgrade, upgrade to the latest supported version.
Don't think about 3.0, why? Because there is no official version yet, let's go to 2.7.
upgrade preparation
code preparation
Before upgrading, remember to pull a new branch. If there is no svn tool, you should make a copy first. Otherwise, the upgrade will fail midway, or a new requirement will be added, and it will be over later.
Dependent on preparation
In order to facilitate everyone to upgrade, the official package has been withdrawn.
The one below is 2.7.0, you can directly modify 2.7.0 to 2.7.2 in the path.
You can directly update the version of the corresponding dependency package without worrying about conflicts.
The second is to add the following integration dependencies. The function of this dependency is that when there are identified and removed properties in your configuration file, the log will print a prompt. Simply put, the invalid configuration of history can be eliminated.
Just add the current maven operation.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-properties-migrator</artifactId>
<scope>runtime</scope>
</dependency>
After the project is normal, remember to delete this.
Of course, if you are a new project, don’t bother so much, just go to start.spring.io and adjust it yourself.
Precautions
1. spring-cloud-starter-bootstrap dependency (optional)
If your project uses the bootstrap configuration file, you need to add the spring-cloud-starter-bootstrap dependency, because in the new version, the bootstrap has been taken out, and it is a separate faction.
If you don't add it, you won't be able to read the value in the configuration file.
spring-cloud-starter-bootstrap 依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
<version>3.1.3</version>
</dependency>
2. Cross-domain settings
addAllowedOrigin("*") is not supported in version 2.7, you need to use addAllowedOriginPattern("*") instead.
3. Interceptor settings
The original interceptor webmvcconfigureadapter has expired, and a new interface WebMvcConfigure needs to be implemented.
4. Configuration file settings
The default matching rules of pathmatch have changed. Need to set the default rule as ant_path_matcher.
spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher
5. swagger settings
For swagger, it is recommended to use springdoc to try it out, which is quite cool to use. It's okay if you don't change it.
Other settings depend on your business. If the package is outdated, just upgrade it.
Summarize
For the overall upgrade, you still need to refer to the official related upgrade documents. My personal suggestion is that if you don’t have the corresponding experience, it’s best not to span too much at once, and you can deal with it in a small version. In this way, the changes in the middle will be relatively small, and problems will be dealt with much faster.