How do I upgrade the Spring version in Spring Boot
Asked Answered
D

2

26

Is there a tutorial on how to upgrade the Spring version to Spring 5.0? I can't find the Spring version in my pom.xml.

I found this: https://github.com/spring-projects/spring-framework/wiki/Upgrading-to-Spring-Framework-5.x#upgrading-to-version-50

But it doesn't give instructions on where to actually change the version number.

I'm using Spring Boot 1.3. If I upgrade to Spring Boot 2.0, will that automatically upgrade my Spring version to 5?

Thanks!

Darice answered 12/6, 2018 at 18:59 Comment(0)
S
26

A Spring Boot project (that is a project using Spring Boot dependencies) has to not explicitly set the individual Spring dependencies. These dependencies are pulled by the Spring Boot core artifact that you declared. That is generally done via the spring-boot-starter-parent that you declare as the parent pom of your project.
And that is a great advantage of Spring Boot that relieves you from identifying and declaring dependencies that work finely together.
So in order to update your project to Spring 5 (the actual released version), you have to update the spring-boot-starter-parent parent declaration from 1.3 to 2.X (or the spring-boot-dependencies' dependency version if you don't use the starter parent).
You can indeed read in the release note of Spring Boot 2 that :

Spring Boot 2.0 builds on and requires Spring Framework 5.

Note that updating from Spring Boot 1.3 (a fair old version) to Spring Boot 2 (a very recent version) may have as consequence some regressions for your application.
So you should take care to test carefully your application to identify all of them.
The Spring-Boot-2.0-Migration-Guide is also a good resource to ease the migration.


To check the version of the Spring dependencies pulled by Spring Boot, you can rely on the dependency:tree goal.
Here is a snippet of what you get by declaring org.springframework.boot:spring-boot-starter:jar:2.0.2.RELEASE as parent of your project :

$ mvn dependency:tree                                                                       
[INFO] Scanning for projects...                                                             
[INFO]                                                                                      
[INFO] ----------------------------------------------------             
[INFO] Building demo 0.0.1-SNAPSHOT                                                         
[INFO] --------------------------------[ jar ]---------------------------------             
[INFO]                                                                                      
[INFO] --- maven-dependency-plugin:3.0.2:tree (default-cli) @ demo ---                      
[INFO] com.example:demo:jar:0.0.1-SNAPSHOT                                                  
[INFO] +- org.springframework.boot:spring-boot-starter:jar:2.0.2.RELEASE:compile            
[INFO] |  +- org.springframework.boot:spring-boot:jar:2.0.2.RELEASE:compile                 
[INFO] |  |  \- org.springframework:spring-context:jar:5.0.6.RELEASE:compile                
[INFO] |  |     +- org.springframework:spring-aop:jar:5.0.6.RELEASE:compile                 
[INFO] |  |     +- org.springframework:spring-beans:jar:5.0.6.RELEASE:compile               
[INFO] |  |     \- org.springframework:spring-expression:jar:5.0.6.RELEASE:compile          
[INFO] |  +- org.springframework.boot:spring-boot-autoconfigure:jar:2.0.2.RELEASE:compile   
[INFO] |  +- org.springframework.boot:spring-boot-starter-logging:jar:2.0.2.RELEASE:compile`
... 

You can make a "dry run" test by generating a sample project via https://start.spring.io/

Sloatman answered 12/6, 2018 at 19:3 Comment(4)
So once I update Spring Boot to 2.0 it will automatically update to Spring 5?Darice
Exactly. I updated my answer to give you some ways to check the Spring version used.Sloatman
Thanks! I'll try following this guide to upgrade Spring Boot: github.com/spring-projects/spring-boot/wiki/…Darice
You are welcome ! I referenced this good link. It may help others. Good update :)Sloatman
P
10

You can find the Spring Framwork version of spring-boot-starter-X by checking its pom.xml. Navigate to its parent pom until you get to spring-boot-dependencies-VERSION.pom. With InteliiJ, in the pom file, I can easily navigate to the parent pom by clicking on the reference in the file. I guess (or hope) you can do the same in other IDEs. Look for the property <spring.version>, that's is the Spring Framwork version.

For example, I am using spring-boot-starter-web-1.3.8.RELEASE.jar. Its parent pom is spring-boot-dependencies-1.3.8.RELEASE which includes the property <spring.version> with the value 4.2.8.RELEASE.

You can change the Spring Framwork version by overriding this property in your pom that includes spring-boot-starter-X dependency, but it is not recommended . Also note that the property name was changed to spring-framework.version on later versions.

Pius answered 5/8, 2019 at 16:24 Comment(1)
It was helpful!Overpower

© 2022 - 2024 — McMap. All rights reserved.