@Qualifier
Artifact
- spring-beans
역할
- @Autowired로 연결한 bean 목록에서 유일한 bean을 구별
memo
Spring은 동일한 타입을 가진 bean 객체가 2개 존재할 경우 어떤 bean을 주입할지 알 수 없기때문에 Exception을 발생시킴
사용법
bean 선언
@Bean
@Qualifier("myWebClient")
public class myWebClient implements WebClient {
...
}
Constructor Injection
public class MyClass {
private final WebClient webClient;
@Autowired
public MyClass(@Qualifier("myWebClient") WebClient webClient) {
this.webClient = webClient;
}
}
Setter Injection
public class MyClass {
private final WebClient webClient;
@Autowired
public setWebClass(@Qualifier("myWebClient") WebClient webClient) {
this.webClient = webClient;
}
}
Field Injection
public class MyClass {
@Autowired
@Qualifier("myWebClient")
private WebClient webClient;
}
댓글남기기