見出し画像

IT忘備録-Springサーバー側の始め方のエラー対処

InteliJ,xampp,MySQL Workbenchを入れ、私はVue.jsでフロント側を書こうとしているためnode.jsをいれ更にvue.cliをインストールした。SPAを作るときだけでなく環境構築は一つの難所に違いない。そう考えながら一気に開発進めていこう!と思ったのだが、、、

Spring initialzrで依存関係の付与など一気に推し進められて便利だが壁に当たった。

ここを見ても正直エラーの具体的な内容は分からない。

public static void main(String[] args) {
		try {
			SpringApplication.run(DemoApplication.class, args);
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}

mainメソッドの中身をtry-catchで囲み具体的な部分を見てみる。(今回はこうしなくてもエラーの詳細は見れるが、try-catchで囲む癖がついたらしい)

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class

まぁ、要するにDataBaseの依存関係を作ったら、DataBaseにつなげよって言われているらしい。だから、application.propertiesに次を記載する。

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/[スキーマ名]//ポート番号は違う可能性あり
spring.datasource.username=[ユーザーネーム]
spring.datasource.password=[パスワード]

取り敢えずこれで指定してあげればOK!開発に戻れる!

余談

try-catchしなくても以下の文面が表れていた。Intellij便利

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


Action:

Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

この記事が気に入ったらサポートをしてみませんか?