Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to upgrade from SpringBoot1.X to 2.X.md

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "SpringBoot1.X how to upgrade to 2.X.md", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "SpringBoot1.X how to upgrade to 2.X.md"!

profile

In the previous department management website, some functions were missing. For example, after initiating a leave application, it was not allowed to take leave for some reasons. At this time, it was found that there was no function to delete leave.

When preparing for feature additions, it was discovered that this project was launched in October 2017, before SpringBoot 2.X was released, so it was still using version 1.X. Since SpringBoot version 1.X has been announced to be out of support and maintenance, I decided to take this opportunity to upgrade to SpringBoot 2.2.0. I encountered some problems and explained them.

Upgrade steps build.gradle file upgrade

The first is to modify the build.gradle file. Since gradle itself is also being upgraded, the changes are not only related to SpringBoot version, but also to Gradle version.

Previous versions used external variables

buildscript { ext { springBootVersion ='1.5.9.RELEASE' }}

At the same time, now that SpringBoot has fully entered the official plug-in library of gradle, it is no longer using the original.

apply plugin: 'java'apply plugin: 'idea'apply plugin: 'org.springframework.boot'apply plugin: 'io.spring.dependency-management'

pattern, but instead uses the new plugins syntax

plugins { id 'org.springframework.boot' version '2.2.0.RELEASE' id 'io.spring.dependency-management' version '1.0.8.RELEASE' id 'java' id 'idea'}

In addition, since JUnit was upgraded from 4 to 5, the related dependencies were also updated.

testCompile('org.springframework.boot:spring-boot-starter-test')

becomes

testImplementation ('org.springframework.boot:spring-boot-starter-test'){ exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'} SpringBoot's settings upgrade

If file uploads are used, the parameters for setting file size limits for uploads have changed after upgrading from 1.X to 2.X

What's even more abnormal is that the settings before 1.4.X and after 1.4.X are different.

1.3.X and earlier versions multipart.maxFileSize=100MBmultipart.maxRequestSize=1000MB1.4 later versions spring.http.multipart.maxFileSize=100MBspring.http.multipart.maxRequestSize=1000MB2.X later versions spring.servlet.multipart.maxFileSize=100MBspring.servlet.multipart.maxRequestSize=1000MB

It's a dead programmer series. Looks like we're gonna have to take a good look at this upgrade guide.

JUnit related upgrades

After upgrading to SpringBoot2 series, the JUnit that comes with it will be upgraded to 5 series, and the above dependencies will also change. Note that junit-vintage-engine is specially removed. This is a JUnit4 compatible test engine. Since the unit tests of the project itself are not many, in order to upgrade completely, the old version will be abandoned. This also causes some changes to the corresponding tests.

The following changes require modification

@RunWith

JUnit4 test, to use Spring's ability, you need @RunWith(SpringRunner.class), but after JUnit5,@SpringBootTest annotation directly helps you add, so you don't need to add this annotation, you can also interact with Spring normally (in fact, JUnit5 also becomes @ExtendWith(SpringExtension.class), but because you don't have to add it manually, you can simply think that you don't need to add @RunWith.

@Test, Assertions

JUnit4 classes such as @Test and assertEquals have been moved from the original package to the new package.

import org.junit.jupiter.api.Test;import static org.junit.jupiter.api.Assertions.*;@ Before, @After, etc.

Some comments in JUnit4 have changed since JUnit5, such as @Before becoming @ Before Each. For specific changes, please refer to here.

Thymeleaf Upgrade

With the SpringBoot version upgrade, Thymeleaf also upgraded from 2.X to 3.0 series, due to a security vulnerability, so after 3.0.10, the onclick function in Thymeleaf template does not allow direct passing of parameters other than numbers and booleans. Modifications are required.

Assuming the value of ${username} is a string, then previous versions

It is correct, but after 3.0.10, it will be wrong. It should be changed to

summary

These are some of the problems and solutions encountered during this upgrade.

At this point, I believe that everyone has a deeper understanding of "SpringBoot1.X how to upgrade to 2.X.md", may wish to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report