Spring Boot 1 series EOL will be reached on August 1, 2019 So, I updated the version of Spring Boot to 2 series (1.5.2
→ 2.1.5
).
Make a note of what you did at that time.
The official migration guide below describes basic migration methods and precautions. Spring Boot 2.0 Migration Guide
I worked while reading the official migration guide, and googled to resolve any unclear points or stumbling points. We also looked at the release notes for major libraries with changing major versions to see if there were any disruptive changes.
spring-boot-properties-migrator
to dependencies (* Remove when migration is complete)In Spring Boot 2, some property keys and settings defined in ʻapplication.properties / ʻapplication.yml
have changed.
If you add spring-boot-properties-migrator
to dependencies, a warning log will be output when the application is started if there are properties whose settings are still out of date. It also temporarily works with the old property writing style.
Add the ↓ line to dependencies. (* Remove when the migration is complete)
build.gradle
runtime "org.springframework.boot:spring-boot-properties-migrator"
In the 1st series, the Dependency Management plugin was included in the Spring Boot plugin, but from the 2nd series, the Dependency Management plugin seems to be different. Add the Dependency Management plugin to build.gradle.
apply plugin: 'org.springframework.boot'
+ apply plugin: 'io.spring.dependency-management' // <--Add this
etx {
- springBootVersion = '1.5.2.RELEASE'
+ springBootVersion = '2.1.5.RELEASE'
}
Increasing the version of Sprin Boot will automatically increase the version of various libraries.
Major changes this time
Also, the RDB connection pool library has changed from Tomcat JDBC
to HikariCP
.
The task bootRepackage
is gone and is now a task named bootJar
build.gradle
bootJar {
mainClassName = 'foo.bar.App'
launchScript() // <--with bootRapackage`executable = true`If you have set, this is an alternative
}
If you have bound Spring Boot properties to Java with @ConfigurationProperties
or @Value
, you need to unify the property name writing to "Canonical".
See Spring Boot 2.0 Canonical Properties for more information.
Basically it was OK if I made all lowercase letters and deleted "-" and "_"
- @ConfigurationProperties(prefix = "foo-bar.apiKey")
+ @ConfigurationProperties(prefix = "foobar.apikey")
5.1. WebMvcConfigurerAdapter→WebMvcConfigurer
The WebMvcConfigurerAdapter
class has been deprecated and changed to the WebMvcConfigurer
interface.
- public class WebMvcConfig extends WebMvcConfigurerAdapter {
+ public class WebMvcConfig implements WebMvcConfigurer {
@GetMapping("/users")
public List<Users> listUsers() {
I prepared an endpoint like this and accessed it from the front end with a path like GET /users.json
, but this is no longer possible.
It's OK to access with GET / users
normally, so I deleted all .json
.
It becomes 5.1
→ 8.0
I searched for com.mysql.jdbc.Driver
and replaced it with com.mysql.cj.jdbc.Driver
.
It becomes 3.9
→ 3.11
.
Due to the new version of JOOQ, some corrections have been made.
It's a good idea to read through the Breaking changes
in The jOOQ Release Note History.
After JOOQ3.11.x
, you need to use gradle-jooq-plugin3.x
plugins {
- id 'nu.studer.jooq' version '2.0.11'
+ id 'nu.studer.jooq' version '3.0.3'
}
Fixed because the API package name has changed
mainDb(sourceSets.main) {
jdbc {
...
}
generator {
- name = 'org.jooq.util.DefaultGenerator'
+ name = 'org.jooq.codegen.DefaultGenerator'
...
database {
- name = 'org.jooq.util.mysql.MySQLDatabase'
+ name = 'org.jooq.meta.mysql.MySQLDatabase'
...
Regenerate the code
while (cursor.hasNext())
- Record record = cursor.fetchOne();
+ Record record = cursor.fetchNext();
The property name of application.properties / application.yml is now flyway. *
→ spring.flyway. *
application.yml.diff
- flyway:
- enabled: true
+ spring:
+ flyway:
+ enabled: true
In Flyway 3 and 4, the execution history of Flyway was managed in a table named schema_version
, but in 5 series it has been renamed to flyway_schema_history
.
To continue using schema_version
, set the property spring.flyway.table
in ʻapplication.properties / ʻapplication.yml
.
application.yml
spring:
flyway:
table: schema_version
Also, if you are using the Flyway plugin in Gradle, set it there as well.
build.gradle
flyway {
...
table = 'schema_version'
}
- implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity4'
+ implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5' // <---Spring Security Dialect version upgrade
The layout notation has changed from Thymeleaf 3. reference:
layout/default.html.diff
<!DOCTYPE html>
<html lang="ja"
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
<meta charset="utf-8"/>
<!-- 「{Title of each page} |It becomes a title like "app name"-->
- <title layout:title-pattern="$CONTENT_TITLE | $DECORATOR_TITLE">app name</title>
+ <title layout:title-pattern="$CONTENT_TITLE | $LAYOUT_TITLE">app name</title>
...
</head>
<body>
<!--Embed common HTML-->
- <div layout:replace="common/header::partial"></div>
+ <div layout:replace="~{common/header::partial}"></div>
<!--Expand the content of each page here-->
<div layout:fragment="content"></div>
</bod>
</html>
sample/index.html.diff
<!DOCTYPE html>
<html
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
xmlns:th="http://www.springframework.org/schema/mvc"
- layout:decorator="layout/default">
+ layout:decorate="~{layout/default}">
<head>
<title>Title of each page</title>
</head>
<body>
<!--Content of each page-->
<div layout:fragment="content">
Hello World
</div>
</body>
</html>
Since it has changed from Tomcat JDBC to Hikari CP, modify the settings.
The property name is
spring.datasource.tomcat.*
→ spring.datasource.hikari.*
Will be.
Items that can be set in HikariCP are in com.zaxxer.hikari.HikariConfig It is defined.
Originally, I defined a task to build the front end in Gradle and set it to be executed when the jar was created.
build.gradle
jar.dependsOn compileFrontend
However, from Spring Boot 2 series, jar is generated by bootJar task, so I changed it as ↓
build.gradle
bootJar.dependsOn compileFrontend
org.dbunit.database.AmbiguousTableNameException: ACCOUNTS
It seems that an error occurs when a table with the same name exists across multiple databases.
I fixed it by adding the query parameter nullCatalogMeansCurrent = true
to the JDBC URL.
(It seems that the default behavior of the JDBC driver for MySQL has changed)
TINYINT (1)
field in JOOQjava.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.Byte
As a policy when using JOOQ, BIT (1)
was mapped to Boolean and TINYINT (1)
was mapped to Byte.
However, after updating to Spring Boot 2, TINYINT (1)
was mapped to Boolean and ClassCastException occurred.
I fixed it by adding the query parameter tinyInt1isBit = false
to the JDBC URL.
MySQL's JDBC driver seems to treat TINYINT (1)
as BIT (1)
internally, and it seems that it has become Boolean.
java.lang.IllegalArgumentException: The character [_] is never valid in a domain name.
It seems that the version of Tomcat has been upgraded and it no longer accepts domain names containing _
.
(It seems strange that the domain name includes _
as an RFC specification.)
→ Since _
was included in the subdomain, I changed the subdomain name to deal with it.
Reference: https://stackoverflow.com/questions/53504857/the-character-is-never-valid-in-a-domain-name
Recommended Posts