Could not autowire. No beans of ‘OOO’ type found.
2023-01-30
MemberRepository 테스트중 @Autowired했는데 Could not autowire. No beans of ‘MemberRepository’ type found. 오류가 발생했다.
-
MemberRepository에 @Repository해도 똑같은 오류 발생.
-
@ComponentScan해보았지만 아래와 같은 오류 발생. No qualifying bean of type ‘kr.co.test.Repository.MemberRepository’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
1.문제원인
@SpringBootApplication main메소드가 선언된 클래스 위치가 문제였다. @SpringBootApplication 가 위치하는 패키지 이하의 모든 클래스가 컴포넌트 스캔이 된다. 하지만 entity, repository 패키지 위치가 상위에 있어 스캔 대상에서 벗어난거였다.
2.해결방법
@SpringBootApplication main메소드가 선언된 클래스 위치를 변경하여 해결하면 된다.
댓글남기기