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.
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>
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
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));
The method of creating ʻorg.springframework.data.domain.Sortobjects in Spring Data has changed from
new 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.
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);
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