Junit 테스트를 진행하는 도중
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'springConfig' defined in file
[C:\Users\Hansol\OneDrive\Desktop\study\hello-spring\SpringBase\build\classes\java\main\hello\hellospring\SpringConfig.class]:
Unsatisfied dependency expressed through constructor parameter 0;
nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException:
No qualifying bean of type 'hello.hellospring.repository.MemberRepository' available:
expected single matching bean but found 2:
jpaMemberRepository,springDataJpaMemberRepository
와 같은에러 가 났다. 대충 읽어보니 설정과 관련된 에러일 것이라 판단되었고
구글링을 해보니 객체 생성을 위한 클래스 어노테이션이 빠졌을거라고 추측한 글들이 많았다.
해결하기 위해 junit테스트 클래스 위에 @WebAppConfiguration을 추가하면 된다고 했지만
그래서 다시한번 에러를 자세히 읽어봤다. 두번째 문단의 글을 읽어보니 SpringConfig에서 Bean을 못 읽어들이는 문제같아 보였고, 한개의 서비스에 매칭되는 레퍼지토리가 2개로 인식되어서 문제가 발생된 것이라고 판단되었다.(표현이 이게 맞나?)
그래서 현재 서비스가 MemberRepository 인터페이스와 연결되어 있는데, JpaMemberRepository에서 @Repository 어노테이션이 사용되어있는 것을 확인했다.