如何在 Spring Boot 中升级 Spring 版本 [英] How do I upgrade the Spring version in Spring Boot

查看:610
本文介绍了如何在 Spring Boot 中升级 Spring 版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关于如何将 Spring 版本升级到 Spring 5.0 的教程吗?我在 pom.xml 中找不到 Spring 版本.

我发现了这个:https://github.com/spring-projects/spring-framework/wiki/Upgrading-to-Spring-Framework-5.x#upgrading-to-version-50

但它没有给出在何处实际更改版本号的说明.

我使用的是 Spring Boot 1.3.如果我升级到 Spring Boot 2.0,是否会自动将我的 Spring 版本升级到 5?

谢谢!

解决方案

Spring Boot 项目(即使用 Spring Boot 依赖项的项目)不必显式设置各个 Spring 依赖项.这些依赖项由您声明的 Spring Boot 核心工件拉取.这通常是通过您声明为项目的父 pom 的 spring-boot-starter-parent 完成的.
这是 Spring Boot 的一大优势,它使您无需识别和声明可以很好地协同工作的依赖项.
因此,为了将您的项目更新到 Spring 5(实际发布的版本),您必须将 spring-boot-starter-parent 父声明从 1.3 更新到 2.X(或 spring-boot-dependencies' 依赖版本(如果您不使用 starter parent).
你确实可以阅读Spring Boot的发行说明2 :

<块引用>

Spring Boot 2.0 基于 Spring Framework 5 构建并需要它.

请注意,从 Spring Boot 1.3(一个相当旧的版本)更新到 Spring Boot 2(一个非常新的版本)可能会导致您的应用程序出现一些回归.
因此,您应该小心地仔细测试您的应用程序以识别所有这些.
Spring-Boot-2.0-Migration-Guide 也是缓解迁移的好资源.

<小时>

要查看 Spring Boot 拉取的 Spring 依赖的版本,可以依赖 dependency:tree 目标.
以下是通过将 org.springframework.boot:spring-boot-starter:jar:2.0.2.RELEASE 声明为项目的父级而获得的片段:

<前>$ mvn 依赖项:树[信息] 正在扫描项目...[信息][信息] ----------------------------------------------------[信息] 构建演示 0.0.1-SNAPSHOT[INFO] --------------------------------[ jar ]---------------------------------[信息][信息] --- maven-dependency-plugin:3.0.2:tree (default-cli) @ demo ---[信息] com.example:demo:jar:0.0.1-SNAPSHOT[信息] +- org.springframework.boot:spring-boot-starter:jar:2.0.2.RELEASE:compile[信息] |+- org.springframework.boot:spring-boot:jar:2.0.2.RELEASE:compile[信息] ||\- org.springframework:spring-context:jar:5.0.6.RELEASE:compile[信息] ||+- org.springframework:spring-aop:jar:5.0.6.RELEASE:compile[信息] ||+- org.springframework:spring-beans:jar:5.0.6.RELEASE:compile[信息] ||\- org.springframework:spring-expression:jar:5.0.6.RELEASE:compile[信息] |+- org.springframework.boot:spring-boot-autoconfigure:jar:2.0.2.RELEASE:compile[信息] |+- org.springframework.boot:spring-boot-starter-logging:jar:2.0.2.RELEASE:compile`...

您可以通过 https://start.spring.io/

通过生成示例项目来进行试运行"测试

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!

解决方案

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/

这篇关于如何在 Spring Boot 中升级 Spring 版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆