[Spring] @Qualifier: 빈 충돌 해결
·
Dev Framework/Spring
@Qualifier: 빈 충돌 해결Spring에서는 @Autowired를 통해 의존성을 자동 주입할 수 있다. 하지만 같은 타입의 빈이 여러 개 등록되어 있을 경우, Spring은 어떤 빈을 주입해야 할지 판단하지 못하고 예외를 발생시킨다. 이럴 때 사용하는 도구가 바로 @Qualifier이다. 1. 문제 상황: 같은 타입의 Bean이 2개 이상일 때다음과 같은 구조를 생각해보자.public interface NotificationService { void send(String message);}@Servicepublic class EmailNotificationService implements NotificationService { public void send(String message)..