Open2

Spring Boot 3.0へのアップデート

eichisandeneichisanden

移行方法のメモ。
Spring Boot 2.7のOSS Supportは2023/11まで

移行ガイド

https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0-Migration-Guide

準備

  • 2.7系の最新に上げる
  • Spring Securityを5.8に上げる
  • Java17に上げる
  • Spring2.xで非推奨だったものは削除されるので修正
  • Groovy 3.0.7以降にアップグレード
  • Gradleを7.5に上げる
    • compileとかruntimeとかがなくなっている
  • build.gradleのJavaバージョン指定を変更
    ついでに現在推奨されるtoolchainを使う書き方に修正する
- sourceCompatibillity = 11
- targetCompatibillity = 11
+ javaCompiler = javaToolchains.compileFor {
+      languageVersion = JavaLanguageVersion.of(17)
+}

Spring Boot 3へアップグレード

  • コンフィギュレーション・プロパティの移行

プロジェクトに依存として下記を追加すると、アプリケーション環境を分析して起動時に診断を表示するだけでなく、実行時に一時的にプロパティを移行することができる。

runtime("org.springframework.boot:spring-boot-properties-migrator")
@Configuration
@EnableWebSecurity
@EnableMethodSecurity
public class SecurityConfig {
    @Bean
    public SecurityFilterChain sercurityFilterChain(HttpSecurity http) throws Exception {
        return http.build();
    }
}
  • mvcMatchers()とantMatchers()は削除されたのでrequestMatchers()を使う

  • Spring WebMVC

    • HandlerInterceptorAdapterがDeprecatedになったので、(Async)HandlerInterceptorを使う方法に置き換える
  • 参考