더북(TheBook)

이 애플리케이션을 그대로 실행하면 스프링이 컨텍스트에서 두 빈 중 어떤 빈을 주입할지 알 수 없어 예외가 발생한다. 다음 코드는 예외 메시지에서 가장 흥미로운 부분을 발췌한 것이다. 이 예외는 스프링이 직면한 문제를 명확히 설명하는데, ‘한 개가 매칭될 것을 예상했지만 두 개가 발견되었습니다(expected single matching bean but found 2)’는 메시지가 포함된 NoUniqueBeanDefinitionException이다. 이는 프레임워크가 컨텍스트에서 주입해야 하는 기존 빈들에 대한 지침이 필요하다는 것을 보여 준다.

Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: 

No qualifying bean of type 'proxies.CommentNotificationProxy' available:
    expected single matching bean but found 2:
commentPushNotificationProxy,emailCommentNotificationProxy

 

신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.