Spring - 중복된 빈 등록에 대한 처리


스프링 의존 객체 선택

  • 컴포넌트 Annotation은 싱글톤 범위로 등록되며 같은 타입의 빈이 다른 클래스에서 등록된 경우 에러가 발생한다.
1
2
3
4
5
6
7
8
9
10
11
12
13
public interface Repository {
}
@Repository
public class Repository2 implements Repository{
}
@Repository
public class Repository3 implements Repository{
}
@Service
public class Service{
@Autowired //등록된 빈이 중복되어 에러 발생
Repository repository;
}
자세히 보기