새소식

Programming/Solving Errors

[Spring Boot] Failed to load ApplicationContext 에러

Spring Boot에서 JdbcTemplate을 이용한 DB 접근(H2)을 위해 테스트코드(JUnit) 작성 후 실행했을 때 발생한 에러.

java.lang.IllegalStateException: Failed to load ApplicationContext

	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:98)
	at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:124)
    ...

 

 

검색해보니 오타가 있을 때도 발생하는 에러인 것 같지만 더블 체크를 해봐도 오타는 없었고,

나의 경우에는 build.gradle 파일에서 dependencies 설정을 제대로 하지 않아 발생하였다.

하기 내용에서 runtimeOnly 부분이 빠져있었음!

implementation 'org.springframework.boot:spring-boot-starter-jdbc'
runtimeOnly 'com.h2database:h2'

 

 

 

코드 수정 후 코끼리 모양의 아이콘(gradle refresh)을 누르고 테스트를 다시 실행해보니

(IDE - IntelliJ)

 

 

 

결과가 성공적으로 나왔다 :)

Contents

Copied URL!

Liked this Posting!