• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    해결됨

@Autowired 필드명으로 빈 조회하기

24.01.08 17:39 작성 조회수 99

0

섹션 7에서 "@Autowired 필드명" 강의를 듣고 있습니다.

AutoAppConfigTest에서 아래와 같은 에러가 발생합니다.

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'orderServiceImpl' defined in file [/Users/a/Desktop/study/spring-study/core/out/production/classes/hello/core/order/OrderServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 1: No qualifying bean of type 'hello.core.discount.DiscountPolicy' available: expected single matching bean but found 2: fixDiscountPolicy,rateDiscountPolicy

 

질문 게시판에 있는 글들도 읽어봤는데 따로 해결방법을 못찾겠습니다.

아래는 관련 코드들 캡쳐해서 첨부합니다.

Screenshot 2024-01-08 at 5.36.29 PM.pngScreenshot 2024-01-08 at 5.36.36 PM.pngScreenshot 2024-01-08 at 5.36.43 PM.pngScreenshot 2024-01-08 at 5.37.18 PM.pngScreenshot 2024-01-08 at 5.37.24 PM.png

답변 1

답변을 작성해보세요.

1

OMG님의 프로필

OMG

2024.01.08

안녕하세요. euneun님, 공식 서포터즈 OMG입니다.

해당 오류가 발생하는 이유는 할인 정책을 정률 할인정책과 정액 할인 정책을 모두 할인정책의 스프링 빈으로 (@Component 적용) 하여 발생하는 오류 입니다.

아래 두 강의 조회 빈이 2개이상 - 문제에서는 이러한 문제에 대해서 확인하고

그 다음 강의인 @Autowired 필드명, @Qualifier, @Primary는 이 문제에 대한 해결책을 제시해주고 계십니다.

아래 강좌를 참고 부탁드립니다 😀

image

해당 오류에 대한 강의자료

image

 

감사합니다.