본문 바로가기
Java/Spring with Error

[해결 방법] Failed to configure a DataSource

by HJ0216 2023. 8. 19.

👉 기본 환경

- Language: Java

- DB: MySQL

- IDE: IntelliJ

 

 

⌨️ 코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
plugins {
    id 'java'
    id 'org.springframework.boot' version '2.7.14'
    id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}
 
group = 'com.example'
version = '0.0.1-SNAPSHOT'
 
java {
    sourceCompatibility = '11'
}
 
configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}
 
repositories {
    mavenCentral()
}
 
dependencies {
    implementation 'org.springframework.boot:spring-boot-devtools'
    implementation 'org.springframework.boot:spring-boot-starter-web'
 
    compileOnly 'org.projectlombok:lombok'
 
    runtimeOnly 'com.mysql:mysql-connector-j'
 
    annotationProcessor 'org.projectlombok:lombok'
 
}
 
tasks.named('test') {
    useJUnitPlatform()
}
 
 
 

 

 

🖨️오류

1
2
3
4
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
 
 
 

 

 

📡 원인

DB 연결 정보가 설정되지 않음

 

 

📰 해결 방법

application.yml에 DB 정보 설정

* application.properties와 동일하나, 문법이 다름

1
2
3
4
5
6
7
spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/mydb?serverTimezone=Asia/Seoul
    username: DB_생성_시_입력한_username
    password: DB_생성_시_입력한_password 
 
 
 

 

 

 

📚 참고 자료

 

Spring error - Failed to configure a DataSource 에러 원인과 해결 방법

Failed to configure a DataSource 에러와 원인과 해결 방법 메시지 Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. *************************** APPLICATION FAILED TO START ********

7942yongdae.tistory.com