LoginSignup
1
1

More than 1 year has passed since last update.

【Spring Boot】schema.sqlが実行されない

Posted at

はじめに

spring JDBCではあらかじめschema.sqlに記載したSQL構文が起動時に実行されますが、なぜか実行されませんでした。
今回解決した方法を本記事で残しておこうと思います。

実行できなかった設定

【shema.sql】

id VARCHAR(8) PRIMARY KEY,
task VARCHAR(256),
deadline VARCHAR(10),
done BOOLEAN
);

【application.properties】

spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:~/S.demo
spring.datasource.username=*.*****
spring.datasource.password=*.*****
spring.sql.init.mode=always
spring.h2.console.enabled=true

解決した方法

記述したSQLはチェックしましたが間違っていなそうだったので、おそらくapplication.propertiesの設定では? と色々検索したところ、
公式ドキュメントで答えになりそうな部分を見つけました。
どうやら記載の仕方に変更があったようです。
地味にこういう変更があるの困りますね、、笑

spring.sql.init.mode=always

ともあれ、上記の記載に変更し、実行したところ、ちゃんとテーブルが作成されていました。

1
1
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
1
1