Spring

[error] Failed to load ApplicationContext

쪽제비 2023. 5. 27. 21:55

TDD 를 적용하여 개발 하던 중 에러가 발생했다.

 

환경

- Spring Boot 2.7.12

- JDK 11

- JUnit 5

 

 

테스트 코드

@SpringBootTest
public class TimeRepositoryTest {

    @Autowired
    TimeRepository timeRepository;
    @Test
    public void save() {
        Time time = Time.builder()
                .group("test")
                .subject("test")
                .date(LocalDateTime.now())
                .duration(Duration.ofMinutes(19))
                .build();

        Time savedTime= timeRepository.save(time);
        assertThat(savedTime).isEqualTo(time);
    }
}

 

발생 에러

- java.lang.IllegalStateException: Failed to load ApplicationContext

 

- 발생한 테스트 메소드에서는 정확한 원인을 알기 어려웠다.

- 테스트 클래스를 클릭해서 로그를 보니 원인을 파악할 수 있었다.

실제 원인

- 아래 캡처 내용 처럼 Datasource 설정에 실패 한 것이다.

- 해결책도 제시해 준다. 임베디드 데이터베이스를 사용하면 해결이 될 것으로 보인다.

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

 

해결

- 해당 에러에 대한 해결은 H2 를 설치하면서 해결 하였다.

dependencies {
	// H2
	implementation 'com.h2database:h2'
}

'Spring' 카테고리의 다른 글

[error] Table not found / Error executing DDL  (0) 2023.05.27