카테고리 없음
[SpringBoot]초기 실행 에러 Failed to configure a DataSource
찬란한
2023. 2. 23. 23:39
에러 발생 히스토리
스프링부트 build.gradle 파일을 open하고 처음 Application을 Run하려고 할 때 다음과 같은 원인 발생했다.
***************************
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).
Process finished with exit code 1
원인
SpringBoot를 실행하면 자동으로 DB 정보를 확인한다.
최초 실행 시 어떤 DB정보를 설정하지 않았기때문에 이와 같은 에러가 발생한다.
대응
위 원인에 따르면 DB정보를 세팅 후 문제가 없겠지만, 일단 DB정보 세팅 여부와는 관계없이 정상적으로 Application Run을 하기 위해서
DB정보를 확인하지 않도록 명령할 수 있다.
package japbook.jpashop;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class JpashopApplication {
public static void main(String[] args) {
SpringApplication.run(JpashopApplication.class, args);
}
}
(exclude = DataSourceAutoConfiguration.class)를 추가였을 경우 위 에러가 발생하지 않는다.