잘 정리해보자
Spring Boot Error : Failed to configure a DataSource 본문
Spring Boot 처음 실행 시, 아래와 같은 에러 발생한다.
에러 메시지 :
***************************
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
원인 :
스프링 부트 설정 시, Application.java 파일에서 @SpringBootApplication 이 선언되있는데, 이 어노테이션에서 DB 정보를 찾는 DataSource config를 찾는데, 정의되어 있지 않으면 발생하는 에러.
@SpringBootApplication
public class ProjectApplication {
...
}
해결방법 :
1. 당장 DB를 사용하지 않고 스프링 부트를 쓸 경우, exclude로 DataSource 클래스 호출을 제외시킨다.
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class ProjectApplication {
...
}
2. DB를 사용하는 경우, application.properties 파일이나 application.yml 파일에 DataSource 정보를 정의한다.
application.yml
spring:
datasource:
url: jdbc:mysql://localhost:3306/database명
username: root
password: password
driver-class-name: com.mysql.jdbc.Driver
'Spring > Spring Boot' 카테고리의 다른 글
Comments