[JAVA] The story of raising Spring Boot from 1.5 series to 2.1 series part2

Introduction

Hi, this is @chan_kaku In the previous article here, I talked about raising from Spring Boot 1.5 series to 2.1 series. This time, I would like to mention the difficulties that I had when I made a full-scale migration following the previous migration.

Why are you writing similar articles

For the target service I wrote in the previous article, I chose the one with as few dependent libraries as possible in order to know in advance the points that I might be addicted to as a preliminary step to the service to be migrated this time. It was. The service targeted this time depends on Spring Cloud etc., so there were many addictive points that were different from the previous time, so I decided to write it again.

What I did (overview)

--Gradle3 series → Gradle5 series --Spring Boot 1.5 series → Spring Boot 2.1 series --Upgrade of other dependent libraries

As for what I did, I feel that there are many things that I wear at the beginning. In this article, I will write the differences from the previous one.

SpringBoot 1.5 series → Spring Boot 2.1 series

Last time, the version upgrade of Spring Boot itself was solved only by adding ʻio.spring.dependency-management`. However, the place where there was a big change from this 1.5 series to 2.1 series was Spring Cloud.

Change 1

Feign Client was the one that had a breaking change in Spring Cloud. In the first place, the package configuration has changed as follows

- import org.springframework.cloud.netflix.feign.FeignClient;
+ import org.springframework.cloud.openfeign.FeignClient;

Originally it used Netflix's Feign Client, but it has changed to Open Feign's Feign Client. Along with this, the interface has changed, and it is necessary to correct that area. (Per FeignClientException)

Since it was a part that connects with external services, we carefully tested it here.

Change 2

The next change is about the default data source in Spring Boot. Tomcat JDBC was used by default in 1.x series. However, HikariCP is used by default from 2.x series. Now that this Hikari CP is used, an error has come out. An error occurred because the version of HikariCP used in SpringBoot 2.x series and the version of HikariCP used in other dependent libraries are different. The story around here was also mentioned in [issue] of Spring Boot (https://github.com/spring-projects/spring-boot/issues/16656), so why not take a look?

approach

This time, I knew that the error was due to a different version of HikariCP, so I guessed that the version of Spring JDBC was different somewhere. However, I didn't know which Spring JDBC version was older, so I used the Gradle command dependencies. This task is a command that can be executed with gradle without adding a dependency, and can be executed as follows

./gradlew dependencies

You can check the dependency tree by executing this command! I looked at the dependency tree generated by this command and found an older version of the library, so I was able to resolve the error by exclude Spring JDBC from there. Specifically, the version of Spring JDBC that the latest version of ʻorg.seasar.doma.boot: doma-spring-boot-starter` depended on was old, so I solved it by excluding Spring JDBC as follows.

build.gradle


implementation("org.seasar.doma.boot:doma-spring-boot-starter:1.1.1") {
        exclude group: "org.springframework.boot", module: "spring-boot-starter-jdbc"
}

Things that haven't been solved yet

With the above workaround, you can now execute the jar. However, when I run bootRun from gradle, I get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
        at jp.furyu.hoge.api.HogeApiApplication.main(HogeApiApplication.java:14)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
        at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 1 more

In this project, the classPath is rewritten with the bootRun option, but this is rewritten because it seems that an error will occur in windows when there are many dependencies of this project. Around here has more details, so please have a look! It seems that bootRun is not possible due to this rewriting of classPath, but I do not know the solution and it is currently under investigation (July 2019). I will add it as soon as I find a solution!

Postscript (2019/8/8)

When naming the jar, until now it was described as follows in the jar option of build.gradle

build.gradle


jar {
    archiveBaseName = "hoge"
    archiveFileName = "${archiveBaseName}.jar"
    version = "1.0.0"
}

There is no problem when making a jar locally, but when making a jar with CI, the root name of the project may be different, and this phenomenon that it does not become ʻarchiveBase.jar` occurred. So, when I wanted to name the jar specified in the CI environment, the workaround I took this time was to add settings.gradle as follows.

settings.gradle


rootProject.name = 'hoge'

By adding rootProject.name to settings.gradle, the name of the jar will not change even in the CI environment.

Finally

SpringBoot 1.5.x series will be EOL in August 2019, so if you haven't supported it yet, you should really hurry, so I hope this article will be helpful for everyone!

Recommended Posts

The story of raising Spring Boot from 1.5 series to 2.1 series part2
The story of raising Spring Boot 1.5 series to 2.1 series
Upgrade spring boot from 1.5 series to 2.0 series
Story when moving from Spring Boot 1.5 to 2.1
What I did in the migration from Spring Boot 1.4 series to 2.0 series
What I did in the migration from Spring Boot 1.5 series to 2.0 series
Try Spring Boot from 0 to 100.
Introduction to Spring Boot Part 1
The story of migrating from Paperclip to Active Storage
05. I tried to stub the source of Spring Boot
I tried to reduce the capacity of Spring Boot
About the function of Spring Boot due to different versions
A story packed with the basics of Spring Boot (solved)
Spring Boot starting from zero Part 2
Spring Boot starting from zero Part 1
I want to control the default error message of Spring Boot
The story of encountering Spring custom annotation
The story of RxJava suffering from NoSuchElementException
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
[Spring Boot] I investigated how to implement post-processing of the received request.
Procedure to make the value of the property file visible in Spring Boot
The story of switching from Amazon RDS for MySQL to Amazon Aurora Serverless
Change the half-width space of STS (Spring Tool Suite) from "u" to "・"
The story of introducing Ajax communication to ruby
Let's check the feel of Spring Boot + Swagger 2.0
The story of adding the latest Node.js to DockerFile
[Spring Boot] How to refer to the property file
03. I sent a request from Spring Boot to the zip code search API
How to set environment variables in the properties file of Spring boot application
Specify the encoding of static resources in Spring Boot
From the introduction of devise to the creation of the users table
How to write Scala from the perspective of Java
A memorandum of addiction to Spring Boot2 x Doma2
Access the built-in h2db of spring boot with jdbcTemplate
Until the use of Spring Data and JPA Part 2
How to use CommandLineRunner in Spring Batch of Spring Boot
Until the use of Spring Data and JPA Part 1
Deploy the Spring Boot project to Tomcat on XAMPP
How to boot by environment with Spring Boot of Maven
A record of studying the Spring Framework from scratch
[Comparison verification] How different is the development productivity of Spring Boot apps from the past?
[Spring Boot] The story that the bean of the class with ConfigurationProperties annotation was not found
Get to the abbreviations from 5 examples of iterating Java lists
Deploy Spring Boot applications to Heroku without using the Heroku CLI
20190803_Java & k8s on Azure The story of going to the festival
The story of migrating a stray batch without an owner from EC2 to a Docker environment
I want to expand the clickable part of the link_to method
[Java] Deploy the Spring Boot application to Azure App Service
Extract SQL to property file with jdbcTemplate of spring boot
The story of throwing BLOB data from EXCEL in DBUnit
Deploy the application created by Spring Boot to Heroku (public) ②
Introduction to Spring Boot ① ~ DI ~
How to get the longest information from Twitter as of 12/12/2016
Introduction to Spring Boot ② ~ AOP ~
Deploy the application created by Spring Boot to Heroku (public) ①
The story of pushing Java to Heroku using the BitBucket pipeline
[Apache Tomcat] The story of using Apache OpenWebBeans to enable CDI
A story that made me regret when a "NotReadablePropertyException" occurred during the development of the Spring Boot application.
Since I switched from Spring Boot (Java) to Ruby on Rails, I summarized my favorite points of Rails.
I want to know the Method of the Controller where the Exception was thrown in the ExceptionHandler of Spring Boot