기본적인 entity와 repository 구현 후 간단한 테스트를 구동하던 중 에러가 발생했다.
처음에 발생한 메세지는 아래와 같다.
에러 메세지 :
Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
시도: 테스트가 BoardProjectApplication 를 인식하지 못 하는 문제라고 하여 테스트 파일에 아래와 같이 추가해주었다.
@SpringBootTest(classes = BoardProjectApplication.class)
하지만 아래와 같은 에러가 발생하면서 테스트가 구동에 실패했다.
에러 메세지:
Configuration error: found multiple declarations of @BootstrapWith for test class
[repository.JpaRepositoryTest]:[@org.springframework.test.context.BootstrapWith(value=org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTestContextBootstrapper.class),
@org.springframework.test.context.BootstrapWith(value=org.springframework.boot.test.context.SpringBootTestContextBootstrapper.class)]
시도 : @BootstrapWith가 중복되어 에러가 발생한다고 @SpringBootTest 을 다시 주석처리 하라고 한다. 아무래도 @SpringBootTest 으로 해결되는 문제가 아니었나보다.
시도 2: 그래서 지우고 대신 @ContextConfiguration(classes = BoardProjectApplication.class) 을 넣었더니 또 에러가 발생했다.
에러 메세지:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type
'repository.ArticleRepository' available: expected at least 1 bean which qualifies as autowire candidate.
Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
상황: NoSuchBeanDefinitionException 이 발생하며, repository.ArticleRepository 유형의 적격한 빈이 없다고 한다.
해결: 하나하나 뜯어보다 보니, repository 디렉토리의 경로가 com.jinseon.boardproject가 아닌 java 바로 하위에 있었다..
경로를 수정해주니 success.
이런 사소한 실수가 정말 찾기 어렵다.