「わたあめ」の調べ物

調べたことを蓄積していきます

SpringBoot + IntelliJ + MySQL(MyBatis)で環境構築にチャレンジ

01. SpringBoot + IntelliJ + MySQL(MyBatis)で環境構築してみた (Windows10) - Qiita

今回は上記のサイトを参考に作ってみました。

■インストールしていったソフトのバージョン
1-1. JDK
 ⇒「jdk-14.0.1」をインストール
1-2. IntelliJ IDEA
 ⇒11.0.4+10-b304.77 amd64
1-3. MySQLをインストールする
 ⇒8.0.0
3. SpringInitializerを使って必要な依存を注入する
 Project:Gradle Project
 Language:Java
 Spring Boot:2.1.14

■結果はエラー
アプリ実行のところでエラー発生。。。
※ビルドは問題なし。

【エラー内容】
Description: Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. Reason: Failed to determine a suitable driver class

【怪しいと思っている2ファイルの内容】
①application.properties
 ⇒spring:
   datasource:
   url:jdbc:mysql://localhost/sampledb
   username:root
  passowrd:root
②build.gradle
 ⇒SpringInitializerでダウンロードしてきた物をコピー

■原因と修正方法
「application.properties」の書き方が間違っていた。。

【修正後】
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/sampledb
spring.datasource.username=user
spring.datasource.password=user

【修正後の実行ログの抜粋】
BUILD SUCCESSFUL in 5s
3 actionable tasks: 2 executed, 1 up-to-date
9:54:17: Task execution finished 'SampleApiApplication.main()'.