2023-01-30

image-20230130115731190

MemberRepository 테스트중 @Autowired했는데 Could not autowire. No beans of ‘MemberRepository’ type found. 오류가 발생했다.

  1. MemberRepository에 @Repository해도 똑같은 오류 발생.

  2. @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.문제원인

image-20230130122214837

@SpringBootApplication main메소드가 선언된 클래스 위치가 문제였다. @SpringBootApplication 가 위치하는 패키지 이하의 모든 클래스가 컴포넌트 스캔이 된다. 하지만 entity, repository 패키지 위치가 상위에 있어 스캔 대상에서 벗어난거였다.

2.해결방법

image-20230130122856306

@SpringBootApplication main메소드가 선언된 클래스 위치를 변경하여 해결하면 된다.

3.참조

root [권남] SpringBoot Test

Byuk.log [Spring boot] 디렉터리 패키지 구조의 선택

댓글남기기