개발 공부/스프링

[SpringBoot] Error - Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

dev_beomgeun 2022. 2. 4. 00:37
728x90

상황

Spring Initializr을 통해서 MySQL 의존성을 추가한 상태

 

IndexController를 테스트용으로 만들고, 서버를 run 시켰더니 마주친 오류

 

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).


Process finished with exit code 0

 

해법 : 위에 써져있듯이, 데이터베이스 의존성만 추가하고 세팅을 하지 않아서 발생한 문제이다.

 

따라서 application.properties에 DataSource에 대한 내용을 적어주면 된다.

 

# MySQL8 설정
spring.datasource.url=jdbc:mysql://localhost:3306/스키마명?useSSL=false&characterEncoding=UTF-8&serverTimezone=UTC
spring.datasource.username=아이디
spring.datasource.password=비밀번호
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

나는 mysql을 사용하기에 mysql 세팅을 해주었다.

 

+ application.properties에 rds 같은 외부 저장소 내용을 세팅할 시

꼭 .gitignore에 application.properties를 추가해줘야 한다.

728x90