본문 바로가기
Dev/Spring

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

by Blue Developer 2023. 11. 25.

안녕하세요.

 

스프링부트 환경설정 후 처음 실행했을 때 발생한 오류와 해결법을 공유하려고 합니다.

 

내용

***************************
APPLICATION FAILED TO START
***************************

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

 

원인 & 해결

/* application.properties */
spring.datasource.url=jdbc:mysql://localhost:3306/[DB Schema]?autoReconnect=true
spring.datasource.username=[DB Username]
spring.datasource.password=[DB Password]
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

/* application.yml */
spring:
  datasource:
    url: jdbc:mysql://localhost:3306/[DB Schema]?autoReconnect=true
    username: [DB Username]
    password: [DB Password]
    driver-class-name: com.mysql.cj.jdbc.Driver

원인을 분석한 결과, DB 연결에 필요한 정보가 없어서 발생한 오류였습니다. application.properties 파일을 확인해봤는데 내용이 비어있었고, 문제를 해결하기 위해 DB 연결에 필요한 정보를 아래와 같이 설정해주고 서버를 재실행했습니다.

 

결과

로그를 확인한 결과, 서버가 정상적으로 실행되는 것을 확인했습니다. 참고로 'com.mysql.jdbc.Driver'는 deprecated 되었으므로 그 대신에 'com.mysql.cj.jdbc.Driver'를 사용할 것을 권장드립니다.

 

오늘 포스팅한 내용이 도움이 되었다면 공감 부탁드립니다 :)

 

감사합니다.

댓글