[Spring] 컴포넌트 스캔에서의 중복 등록에 의한 오류

Fraise_KIM·2023년 8월 12일
0

⛔️ 컴포넌트 스캔에서의 중복 등록에 의한 오류 (1)

  • 컴포넌트 스캔에서 동일한 빈 이름을 등록한 경우

ConflictingBeanDefinitionException

  • Annotation-specified bean name 'service' for bean class [spring01.core.order.OrderServiceImpl] conflicts with existing, non-compatible bean definition of same name and class [spring01.core.member.MemberServiceImpl]

    => 중복된 빈 이름을 특정해 주고, 어떤 클래스들에서 중복된 빈 이름이 등록되었는지도 친절하게 알려 준다.


💡 해결 : 빈 이름을 다르게 지정해 주면 된다.




⚠️ 컴포넌트 스캔에서의 중복 등록에 의한 오류 (2)

  • 컴포넌트로 자동 등록한 빈과 수동 등록한 빈이 충돌하는 경우

Overriding bean definition for bean 'memoryMemberRepository' with a different definition: replacing

=> 이 경우 에러가 나지는 않지만, 실제로 의도한 빈 등록과 다르게 등록되어 다른 결과가 나올 수 있다.


A bean with that name has already been defined in file [경로] and overriding is disabled.

만약 이 경우 오류가 나지 않게 하고 싶다면, application.properties 아래를 추가하면 된다.

0개의 댓글