본문 바로가기
Spring

[Springboot] (오류 해결) app 실행 시 Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. 오류

by sgyeong 2024. 4. 3.

***************************

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

 

 

문제 원인 


pom.xml에 데이터베이스를 사용하기 위한 dependency가 존재하는 경우 @SpringBootApplication에서 자동으로 데이터베이스 값을 설정하려고 시도하지만 사용자는 데이터베이스 값 입력을 안 했기 때문에 발생하는 오류이다.

 

 

 

해결방법 

 

다음 세 가지 방법 중 하나를 선택한다.

 

첫번째 방법 

application.properties 또는 application.yml 파일에 데이터 소스 추가

properties

spring.datasource.url=

spring.datasource.username=

spring.datasource.password=

spring.datasource.driver-class-name=

 

 

 

yml

spring:

    datasource:

        driver-class-name:
        url:

        username:

        password:

 

 

 

 

두번째 방법 

Configuration 생성 (Bean을 이용하여 DB사용)
별도의 클래스를 생성한다.

import javax.sql.DataSource;

 

import org.springframework.boot.jdbc.DataSourceBuilder;

import org.springframework.context.annotation.Bean;

import org.springframework.context.annotation.Configuration;

 

@Configuration

public class DBConfiguration {

 

        @Bean

        public DataSource datasource()  {

                return DataSourceBuilder.create()

                .driverClassName("")

                .url("")

                .username("")

                .password("")

                .build();

        }

}

 

 

 

 

세번째 방법

DataSourceAutoConfiguration 제외 (DB를 사용하지 않는다는 의미)

springboot생성 시 자동으로 생성되는 Application.java의 @SpringBootApplication 옆에 다음을 추가해준다.

(exclude={DataSourceAutoConfiguration.class})

 

 

 

 

 

 

참고 :  https://hodolee246.tistory.com/9

 

Spring Boot DB 오류해결

0. Github https://github.com/hodolee246/on-my-own/tree/master/DBConfig 1. 개요 Spring Boot 프로젝트에서 오류 원인 및 해결방법 "Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configure

hodolee246.tistory.com

 

'Spring' 카테고리의 다른 글

[Thymeleaf] Thymeleaf 기초  (0) 2025.08.29
[Spring Security] JWT(JSON Web Token)  (2) 2025.08.03
[Spring] 의존성 주입  (1) 2024.11.15
[Springboot] Spring boot 프로젝트 만들기  (0) 2024.04.17