Spring Boot 2.6.6 へアップグレード

この記事を参考に、利用しているプロジェクトのSpring Bootのバージョンを2.6.6へアップグレードする

dev.classmethod.jp

1. データベースへ接続無し

Spring BootのバージョンアップのみでOK

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
-  <version>1.5.2.RELEASE</version>
+   <version>2.6.6</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

Application クラスへ @SpringBootApplication を付与する必要があった

+@SpringBootApplication
-@EnableAutoConfiguration
-@ComponentScan
-@Configuration
public class Application {

あと、src/main/resources/static/index.html を参照できなくなった

2. PostgreSQLへ接続

Spring Bootのバージョンアップに加え以下を実施

PostgreSQLへ接続するためのドライバが古かったので更新 大きな変更があると困るので、なるべく既存のものに近いものを選んだ

<dependency>
-  <groupId>postgresql</groupId>
+   <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
-  <version>9.1-901-1.jdbc4</version>
+   <version>9.4.1212</version>
</dependency>

RestTemplateBuilder の引数が long から Duration になった

restTemplate = restTemplateBuilder
-      .setConnectTimeout(3000)
+       .setConnectTimeout(Duration.ofMillis(3000))
-      .setReadTimeout(3000)
+       .setReadTimeout(Duration.ofMillis(3000))
        .build();

Thymeleafを利用

レイアウトが処理されないので、バージョンの指定を削除

<dependency>
    <groupId>nz.net.ultraq.thymeleaf</groupId>
    <artifactId>thymeleaf-layout-dialect</artifactId>
-  <version>2.4.1</version>
</dependency>

レイアウトファイルの指定方法を変更

<html lang="ja"
    xmlns:th="http://www.thymeleaf.org"
    xmlns:sec="http://www.thymeleaf.org/extras/spring-security"
    xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
-  layout:decorator="backend/layout">
+   layout:decorate="backend/layout">

テスト

テストケースの@ContextConfiguration アノテーションの引数が変わった

-@ContextConfiguration(classes = Application.class, initializers = ConfigFileApplicationContextInitializer.class)
+@ContextConfiguration(classes = Application.class, initializers = ConfigDataApplicationContextInitializer.class)

以下の定義を追加しないとJenkinsでテストが実行されない

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-engine</artifactId>
    <version>5.8.2</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <version>5.8.2</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.vintage</groupId>
    <artifactId>junit-vintage-engine</artifactId>
    <version>5.8.2</version>
    <scope>test</scope>
</dependency>

spring-boot-starter-test があるから不要なんじゃないかと思い削除

-<dependency>
-  <groupId>junit</groupId>
-  <artifactId>junit</artifactId>
-  <version>4.12</version>
-  <scope>test</scope>
-</dependency>

その他

Beanの循環参照があったので見ないふり…

spring:
  main:
+    allow-circular-references: true

コンテキストパスの指定方法が変わった

-System.setProperty("server.context-path", "/path");
+System.setProperty("server.servlet.context-path", "/path");