Changes when migrating from Spring Boot 2.0 to Spring Boot 2.2

Introduction

I will write the correction points when migrating the Spring Boot 2.0.2 application (about 7KL, SPA server part) to Spring Boot 2.2.5.

Spring Boot fixes

Maven

I was using JUnit 5, but in Spring Boot 2.0 junit-platform-launcher and mockito-junit-jupiter, which were not under the control of spring-boot-starter-parent, are now under the control of Spring Boot 2.2. It is no longer necessary to specify the version.

SpringBoot2.0


<dependency>
  <groupId>org.junit.platform</groupId>
  <artifactId>junit-platform-launcher</artifactId>
  <version>1.3.1</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>org.mockito</groupId>
  <artifactId>mockito-junit-jupiter</artifactId>
  <version>2.22.0</version>
  <scope>test</scope>
</dependency>

SpringBoot2.2


<dependency>
  <groupId>org.junit.platform</groupId>
  <artifactId>junit-platform-launcher</artifactId>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>org.mockito</groupId>
  <artifactId>mockito-junit-jupiter</artifactId>
  <scope>test</scope>
</dependency>

Bean overwrite settings

In Spring Boot 2.0, when the same bean is defined, the bean with @Primary is prioritized, but in Spring Boot 2.2, a BeanDefinitionOverrideException exception is thrown at initialization.

Caused by: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'taskExecutor' defined in mypackage.TestConfiguration: Cannot register bean definition [Root bean: class [null]; scope=; abstract=false; lazyInit=null; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=true; factoryBeanName=testConfiguration; factoryMethodName=taskExecutor; initMethodName=null; destroyMethodName=(inferred); defined in mypackage.TestConfiguration] for bean 'taskExecutor': There is already [Root bean: class [null]; scope=; abstract=false; lazyInit=null; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=mainConfig; factoryMethodName=taskExecutor; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [mypackage/MainConfig.class]] bound.

To avoid this, set the spring.main.allow-bean-definition-overriding property in application.yml.

SpringBoot2.0


spring:
  main:
    allow-bean-definition-overriding: true

RestTemplateBuilder setting value type change

When setting RestTemplate using RestTemplateBuilder, the timeout setting has been changed from millisecond specification to java.time.Duration specification, making the unit easier to understand.

SpringBoot1.5


new RestTemplateBuilder()
    .setConnectTimeout(5000)
    .setReadTimeout(60000);

SpringBoot2.0


new RestTemplateBuilder()
    .setConnectTimeout(Duration.ofMillis(5000))
    .setReadTimeout(Duration.ofMillis(60000));

Change how to generate Sort object

The method of creating ʻorg.springframework.data.domain.Sortobjects in Spring Data has changed fromnew to by`.

SpringBoot1.5


new Sort(Sort.Direction.fromString(sortDirection), sortColumn);

SpringBoot2.0


Sort.by(Sort.Direction.fromString(sortDirection), sortColumn);

It seems that it has moved to the servlet package under the security package.

Other

This was originally badly implemented, but in the JPA repository interface method

List<Auth> findByRoleContains(Collection<Role> roles);

I didn't use it. If you change to Spring Boot 2.2 and start the app,

Caused by: java.lang.IllegalStateException: Operator CONTAINING on role requires a scalar argument, found interface java.util.Collection in method public abstract java.util.List mypackage.repository.AuthRepository.findByRoleContains(java.util.Collection).

Exception has occurred.

Contains is a search that includes strings, and I should use In instead of Contains. Why was there no problem so far? .. (I didn't notice it because I didn't use it)

List<Auth> findByRoleIn(Collection<Role> roles);

Summary

It was a lot easier than When I upgraded from Spring Boot 1.5 to 2.0, but it's still a bit of a destructive fix, so be careful. Is required.

Recommended Posts

Changes when migrating from Spring Boot 1.5 to Spring Boot 2.0
Changes when migrating from Spring Boot 2.0 to Spring Boot 2.2
Story when moving from Spring Boot 1.5 to 2.1
Try Spring Boot from 0 to 100.
Upgrade spring boot from 1.5 series to 2.0 series
Precautions when migrating from VB6.0 to JAVA
Changes from Java 8 to Java 11
Introduction to Spring Boot ① ~ DI ~
Introduction to Spring Boot ② ~ AOP ~
Major changes in Spring Boot 1.5
Introduction to Spring Boot Part 1
Spring Boot validation message changes
The story of raising Spring Boot from 1.5 series to 2.1 series part2
What I fixed when updating to Spring Boot 1.5.12 ・ What I was addicted to
How to write and notes when migrating from VB to JAVA
ClassCastException occurs when migrating from Java7 to Java8 ~ Generics and overload ~
[Opens aml] NoClassDefFoundError occurs when migrating from Tomcat to weblogic
Notes on character encoding when migrating from windows to Mac
Memorandum of understanding when Spring Boot 1.5.10 → Spring Boot 2.0.0
How to set Spring Boot + PostgreSQL
Notes on migrating from CircleCI 1.0 to 2.0
How to use ModelMapper (Spring boot)
Spring Boot starting from zero Part 2
Spring Boot starting from zero Part 1
02. I made an API to connect to MySQL (MyBatis) from Spring Boot
Change Spring Boot REST API request / response from CamelCase to SankeCase
What I did in the migration from Spring Boot 1.4 series to 2.0 series
Spring Boot 2.0 Actuator, 3 changes you need to know to get it working
What I did in the migration from Spring Boot 1.5 series to 2.0 series
What I thought about when I started migrating from Java to Kotlin
[Introduction to Spring Boot] Form validation check
Major changes related to Spring Framework 5.0 Test
Transition from Struts2 to Spring MVC (Controller)
Javaw.exe error when starting Spring Boot (STS)
How to split Spring Boot message file
Add spring boot and gradle to eclipse
Troubleshooting when raising Mastodon from v3.0.x to v3.1.x
How to apply thymeleaf changes to the browser immediately with #Spring Boot + maven
How to not start Flyway when running unit tests in Spring Boot
Major changes related to Spring Framework 5.0 Web MVC
[Reverse lookup] Spring Security (updated from time to time)
Use Thymeleaf text template mode from Spring Boot
How to use MyBatis2 (iBatis) with Spring Boot 1.4 (Spring 4)
How to use built-in h2db with spring boot
03. I sent a request from Spring Boot to the zip code search API
How to make Spring Boot Docker Image smaller
How to use Spring Boot session attributes (@SessionAttributes)
The story of raising Spring Boot 1.5 series to 2.1 series
[Spring Boot] How to get properties dynamically from a string contained in a URL
Try to implement login function with Spring Boot
When @Transactional of Spring Boot does not work
Major changes related to Spring Framework 5.0 DI container
How to add a classpath in Spring Boot
Migrating from Eclipse server function (Tomcat) to Embed Tomcat
An introduction to Spring Boot + in-memory data grid
When you want to notify an error somewhere when using graphql-spring-boot in Spring Boot
Annotation notes when writing tests for Spring Boot
Spring Boot Form
How to bind to property file in Spring Boot
Try to automate migration with Spring Boot Flyway
[Java] Article to add validation with Spring Boot 2.3.1.