728x90
반응형
스프링부트 테스트 코드를 실행했는데 에러가 발생했다
Parameter 0 of constructor in hello.core.member.MemberServiceImpl required a single bean, but 2 were found ...
해당 생성자의 파라미터에는 단일 bean이 필요한데 2개가 발견됐다
- AppConfig의 memberRepository
-MemoryMemberRepository의 memoryMemberRepository
에러 내용을 더 확인해보자
- Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'memberServiceImpl' defined in file [~\classes\hello\core\member\MemberServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0: No qualifying bean of type 'hello.core.member.MemberRepository' available: expected single matching bean but found 2: memoryMemberRepository,memberRepository
- Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'hello.core.member.MemberRepository' available: expected single matching bean but found 2: memoryMemberRepository,memberRepository
세번째 같은 말을 하고 있다
확인 결과, 같은 타입인데 이름이 다른 두개의 빈이 있었다
두둥탁
수동 빈 생성
자동 빈 생성
그래서 나는 @Primary로 조회할 빈에 우선순위를 부여해줬다
728x90
반응형
'Spring' 카테고리의 다른 글
[Spring] web.xml (0) | 2025.08.20 |
---|---|
[Spring] 스프링 프레임워크 / 스프링 모듈 (0) | 2025.08.20 |
[Spring] log4jdbc 라이브러리로 sql 로그 파라미터 값까지 출력하기 (0) | 2023.08.08 |
[Spring] 로깅 프레임워크 개념 및 종류(+log4j2 설정) (0) | 2023.07.28 |