spring boot起動時にschema.sqlが実行されないのでアドバイスいただきたいです。。

ファイルの内容

application.properties

spring.datasource.url=jdbc:mysql://localhost:3306/task spring.datasource.username=root spring.datasource.password= spring.thymeleaf.prefix=file:src/main/resources/templates/ spring.mvc.hiddenmethod.filter.enabled=true spring.jpa.hibernate.ddl-auto=none spring.datasource.initialization-mode=always spring.datasource.sql-script-encoding=UTF-8

schema.sql

create database if not exists task;

エラー内容

Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

試したこと


spring.datasource.initialization-mode=alwaysspring.sql.init.enabled=trueに変えて実行してみる
参考
https://qiita.com/t-yama-3/items/9574f34ccc18de30d625

結果
上記エラー内容と変わらず、schema.sqlが実行されない



spring.sql.init.mode=alwaysをapplication.propertieisに追加してみる
参考
https://zenn.dev/rajiku/articles/b70999251195d9

結果
上記エラーに加えて以下のエラーが追加される

Caused by: org.springframework.jdbc.datasource.init.UncategorizedScriptException: Failed to execute database script; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLSyntaxErrorException: Unknown database 'task'

結果
schema.sqlは実行されてない



spring.datasource.schema=classpath:schema.sqlを追加してみる
参考
https://qiita.com/niwasawa/items/af6c5485c1c71d55d7dd

結果
上記エラー内容と変わらず、schema.sqlが実行されない

ちなみに

当たり前かとは思いますが、手動でmysqlに入ってテーブル等を作成すれば
問題なく、実行できています。

もし、わかる方がいらっしゃったら、アドバイスいただけたら幸いです。
あと、足りない情報等もございましたら、ご指摘ください。

よろしくお願いいたします。

コメントを投稿

0 コメント