본문 바로가기

Spring

[SpringBoot] DB 연결 없이 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


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 (the profiles burger are currently active).

DB연결 사용하지 않고 실행하게 되면 위 에러가 발생하게 된다.

 

원인

SpringBoot는 실행하게 되면 자동으로 DB의 정보를 요구하게 되는데 DB를 사용하지 않는다면 이 정보를 application.yml(properties)파일에 명시하지 않는다. 이때 Spring Boot에서 DB 연결 정보를 찾지 못해 해당 에러가 발생하게된다.

spring:
  datasource:
    driver-class-name:
    url:
    username:
    password:

 

해결

//kotlin
@SpringBootApplication(exclude= [DataSourceAutoConfiguration::class])
//java
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})

Application 클래스의 @SpringBootApplication 주석에 exclude 옵션 추가

 

------------------------------------------------------------

해당 annotation 옵션을 추가하게 되면 entityManager가 spring bean으로 등록되지 않거나 등록 되었는데 인식 또는 주입이 안 되는 문제가 발생할 수 있음.

반응형