Spring Boot Failed to configure a DataSource

@ZungTa · 2024-08-07 수요일 · 1 min read

Spring Data JPA 의존성을 사용할 때 이런 오류가 발생할 수 있다.

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

h2 의존성 추가를 해주면 해결할 수 있다.

// build.gradle

...

dependencies {
    ...
    runtimeOnly 'com.h2database:h2'
}

또는 DB 연결 정보를 환경 설정 파일에 입력해주면 된다.

DB 연결할 때는 드라이버가 필요하다.

// build.gradle

// mysql driver
runtimeOnly 'com.mysql:mysql-connector-j'
# application.yaml

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/db_name
    username: user
    password: pwd
    driver-class-name: com.mysql.cj.jdbc.Driver
@ZungTa
I'm a backend developer
© ZungTa Devlog, Built with Gatsby