実現したいこと
参考書の「spring framework超入門」というのを参考にクイズをデータベースに登録する
ようにコードを書いたのですが、JavaファイルをSpring Boot アプリケーションをクリックして実行したのですが、エラーが表示されました。
エラーの内容は恐らく、デバッグを有効にして欲しいという事とJDBC関連だと思ったのですが、その対処方法は未だに分かっていません。
発生している問題・エラーメッセージ
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
・deepl翻訳
ApplicationContextの起動にエラーが発生しました。条件評価レポートを表示するには、「デバッグ」を有効にしてアプリケーションを再実行します。
新しく発覚したエラー
Error creating bean with name 'quizRepository': Unsatisfied dependency expressed through method 'setDialect' parameter 0: Error creating bean with name 'jdbcDialect' defined in class path resource [org/springframework/boot/autoconfigure/data/jdbc/JdbcRepositoriesAutoConfiguration$SpringBootJdbcConfiguration.class]: Failed to instantiate [org.springframework.data.relational.core.dialect.Dialect]: Factory method 'jdbcDialect' threw exception with message: Failed to obtain JDBC Connection
Error creating bean with name 'jdbcDialect' defined in class path resource [org/springframework/boot/autoconfigure/data/jdbc/JdbcRepositoriesAutoConfiguration$SpringBootJdbcConfiguration.class]: Failed to instantiate [org.springframework.data.relational.core.dialect.Dialect]: Factory method 'jdbcDialect' threw exception with message: Failed to obtain JDBC Connection
Failed to instantiate [org.springframework.data.relational.core.dialect.Dialect]: Factory method 'jdbcDialect' threw exception with message: Failed to obtain JDBC Connection
Failed to obtain JDBC Connection
実行したJavaファイル
QuizApplication.java
1package com.example.quiz; 2 3import org.springframework.beans.factory.annotation.Autowired; 4import org.springframework.boot.SpringApplication; 5import org.springframework.boot.autoconfigure.SpringBootApplication; 6 7import com.example.quiz.entry.Quiz; 8import com.example.quiz.repository.QuizRepository; 9 10@SpringBootApplication 11public class QuizApplication { 12 /** 起動メソッド */ 13 public static void main(String[] args) { 14 SpringApplication.run(QuizApplication.class, args) 15 .getBean(QuizApplication.class).execute(); 16 } 17 /** 注入 */ 18 @Autowired 19 QuizRepository repository; 20 /** 実行メソッド */ 21 private void execute() { 22 //登録処理 23 setup(); 24 //全件取得 25 //showList(); 26 } 27 /** === クイズを2件登録します === */ 28 private void setup() { 29 //エンティティ生成 30 Quiz quiz1 = new Quiz(null, "「Spring」はフレームワークですか?", true, "登録太郎"); 31 //登録実行 32 quiz1 = repository.save(quiz1); 33 //登録確認 34 System.out.println("登録したデータは、" + quiz1 + "です。"); 35 //エンティティ生成 36 Quiz quiz2 = new Quiz(null, "「Spring MVC」はバッチ処理機能を提供しますか?", false, "登録太郎"); 37 //登録実行 38 quiz2 = repository.save(quiz2); 39 //登録確認 40 System.out.println("登録したデータは、" + quiz2 + "です。"); 41 } 42 43 /** === 前権取得 === */ 44 private void showList() { 45 System.out.println("--- 前権取得開始 ----"); 46 // リポジトリを仕様して前権取得を実施、結果を取得 47 Iterable<Quiz> quizzes = repository.findAll(); 48 for (Quiz quiz : quizzes) { 49 System.out.println(quiz); 50 } 51 System.out.println("--- 全権取得完了 ---"); 52 } 53}
application.properties
1spring.datasource.driver-class-name=org.postgresql.Driver 2spring.datasource.url=jdbc:postgresql://localhost:5432/quizdb 3springdatasource.username=postgres 4spring.datasource.password=postgres
試したこと
デバッグ実行をしてから再度、実行を行ったのですが同様のエラーが表示されました。
補足情報(FW/ツールのバージョンなど)
開発ツール:Eclipse
Javaバージョン:11
データベース:postgres12
書籍と自身の環境のバージョンでいうと、私は2022年版のEclipseを使用しています。
参考書のEclipseのバージョンと違うかもしれません。