0
3

More than 3 years have passed since last update.

SpringBoot 2.5からschema/dataの指定方法が変わった

Posted at

概要

SpringBootのversion 2.5が最近リリースされたようです。
劇的な変化があるのかはまだわかりませんが、application.ymlのspring.datasource.schemaspring.datasource.dataspring.datasource.initialization-modeに該当する設定部分に警告が出ていたので、その対応(警告が出ないように対応)をしたのでメモとして残します。

警告の内容

以下のような警告が出ています。
内容を見ると、いずれも*** is Deprecatedとなっているので、従来の設定が非推奨となったようです。
代わりにspring.sql.init.***を使ってね。と丁寧に教えてくれているので、設定を変更してみます。

説明  リソース    パス  ロケーション  タイプ
Property 'spring.datasource.data' is Deprecated: Use 'spring.sql.init.data-locations' instead.  application-local.yml   /restcontroller-sample/src/main/resources   行 32  言語サーバー
Property 'spring.datasource.initialization-mode' is Deprecated: Use 'spring.sql.init.enabled' instead.  application-local.yml   /restcontroller-sample/src/main/resources   行 33  言語サーバー
Property 'spring.datasource.schema' is Deprecated: Use 'spring.sql.init.schema-locations' instead.  application-local.yml   /restcontroller-sample/src/main/resources   行 31  言語サーバー

application.ymlの修正

以下のように修正することで、警告表示は消えました。
今までspring.datasourceにまとめて定義していたものを、分割するようになったんですね。

修正前
spring:
  datasource:
    driver-class-name: org.h2.Driver
    url: jdbc:h2:mem:testdb;DB_CLOSE_DELAY=1;DB_CLOSE_ON_EXIT=FALSE;MODE=DB2
    username: sa
    password: ''
    schema: classpath:develop-resources/schema.sql
    data: classpath:develop-resources/data.sql
    initialization-mode: always
修正後
spring:
  datasource:
    driver-class-name: org.h2.Driver
    url: jdbc:h2:mem:testdb;DB_CLOSE_DELAY=1;DB_CLOSE_ON_EXIT=FALSE;MODE=DB2
    username: sa
    password: ''
  sql:
    init:
      enabled: true
      schema-locations: classpath:develop-resources/schema.sql
      data-locations: classpath:develop-resources/data.sql
0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3