안녕하세요 강사님 질문이있습니다.
3528
작성한 질문수 47
12:48 처럼 AutoAppConfig 테스트를 해보았는데요.
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'memberServiceImpl' defined in file : Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'hello.core.member.MemberRepository' available: expected single matching bean but found 3: memoryMemberRepository,memberRepository1,memberRepository2
이러한 에러가 발생하는데요. 찾아보니
@Autowired 사용시에는 동일한 타입을 Bean 객체를 2개사용하지 말것. 이라고 나와있더라구요.
그래서 어디쪽을 살펴보면 좋을까요..?
답변 2
4
제 생각에는 AutoAppConfig 파일이 어떤 디렉터리 안에 있는지 확인해보세요!
hello.core 밑에 있는건지, hello.core.member 폴더에 있는지요
만약 hello.core.member 밑이면 hello.core로 옮기시구요!
0
안녕하세요. 제가 강의 자료 보면서 다시 하니까 중간에 빼먹고 안한게 있더라구요. 그거 때문에 안된거 같습니다 ! 중간에 제 노트로 정리하면서 빼먹었나 봅니다...
답변 감사합니다 !
2
안녕하세요. 조재연님, 공식 서포터즈 OMG입니다.
조재연님이 작성한 코드를 봐야 알겠지만 우선,
======
12:48 처럼 AutoAppConfig 테스트를 해보았는데요.
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'memberServiceImpl' defined in file : Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'hello.core.member.MemberRepository' available: expected single matching bean but found 3: memoryMemberRepository,memberRepository1,memberRepository2
======
올려주신 에러는

에러와 동일한 것으로 보입니다. 해당 Config파일은 SameBeanConfig인데 AutoAppConfig에서도 동일한 에러가 출력되는 것으로 보아 해당 부분에 문제가 있는 것 같습니다.
해당 테스트코드와 MemberRepository, MemberRepositoryImpl, Config 클래스에 대해서 메뉴얼과 비교해보신 후 확인해봐도 해결이 어려울 경우 아래 링크를 참고하여 전체 프로젝트 코드를 공유해주세요.
https://blog.naver.com/aufcl856/221818787116
감사합니다.
0
넵! 저 같은 경우는 MemberRepository, MemberRepositoryImpl, Config 클래스 를 다시 확인해봤는데 똑같더라구요.. 그래서 ApplicationContextSameBeanFindTest 이 테스트 파일을 다시 작성했더니 해결되었습니다..(?)
근데 이렇게 작성이 되있는데 No qualifying bean of type 'hello.core.discount.DiscountPolicy' available: expected single matching bean but found 2: fixDiscountPolicy,rateDiscountPolicy <- 이 에러가 발생하더라구요.
그래서 구글링 해보니까 다른분들도 비슷한 에러가 발생되고 조회 대상 빈이 2개 이상일 때 해결방법 3가지가 소개되있긴 하는데 그건 이 다음 챕터에 바로 소개가 되는데 강사님 자료에는 잘 나온다고 되어있어서 다시 코드 체크중입니다. ㅜ
@Component
public class RateDiscountPolicy implements DiscountPolicy
@Component
public class FixDiscountPolicy implements DiscountPolicy
@Component
public class OrderServiceImpl implements OrderService {
private final MemberRepository memberRepository;
private final DiscountPolicy discountPolicy;
@Autowired
public OrderServiceImpl(MemberRepository memberRepository, DiscountPolicy discountPolicy) {
this.memberRepository = memberRepository;
this.discountPolicy = discountPolicy;
}
0
늦었지만 덧글 달아드립니다. AppConfig에서는 DisCountPolicy로 무엇을 사용할지 fixed or rate로 지정했었는데 AutoAppConfig로 넘어오게 되면서 그냥 단순히 DiscountPolicy에게 Autowired하면 무엇을 넣을지 spring이 알지 못하게 된겁니다. 오류도 그래서 NoUniqueBeanDefinition입니다. 따라서 fix 나 rate중에 하나만 Componentscan을 하면 정상 동작합니다.
코드 자료
0
30
2
구현체가 동적으로 정해질 때, 팩토리 기법을 사용하나요?
0
51
2
MemberService의 인터페이스를 왜 사용하는지 궁금합니다.
0
75
1
롬복 @Setter를 써야 하는 상황이 있는건가요?
0
89
1
빈 등록 메서드의 파라미터가 빈이 아니어도 되나요?
0
81
1
테스트 속도가 나중에 영향이 있을까요?
0
77
1
gradle 설정 안떠서 질문 남깁니다!
0
121
2
build.gradle로 프로젝트를 여는 이유
0
85
1
provider 사용하는 이유
0
88
1
다음 강의 뭘 들어야 할까요
0
126
2
프로토타입 빈, 직접 destroy 호출 안 할 경우
0
64
1
beanB
0
82
2
퀴즈다시풀기
0
67
1
Gradle로 바꿔도 오류가 똑같이 발생하네요 ㅠㅠ
0
92
2
"중복 등록과 충돌" 강의에서 강사님과 다른 에러가 발생합니다.
0
66
3
run 실행했는데 결과창이 이렇게 뜨네요 왜 그런건가요>
0
106
2
도메인의 정의?
0
59
1
ApplicationContext 질문입니다.
0
63
1
@Scope의 proxyMode를 사용할때 단위 테스트 방법
0
88
2
ai api 선정하기 관련 질문
0
118
2
생성자 자동주입 관련해서
0
64
1
생성자 직접 호출 vs 팩토리 메서드 패턴
0
96
2
Spring에서 SessionScope와 RequestScope는 함께 사용되나요?
1
65
1
12:25
0
77
2





