Why do we use qualifiers with @Bean when we can have different names for different beans of the same type (class)?
@Bean
@Qualifier("fooConfig")
public Baz method1() {
}
Isn't the following code more clean?
@Bean("fooConfig")
public Baz method1() {
}
If I create two beans of the same type with different names (using @Bean annotation), then can we inject them specifically using the @Qualifier annotation(can be added on field/constructor parameter/setter) in another bean?
@Bean("fooConfig")
public Baz method1(){
}
@Bean("barConfig")
public Baz method2(){
}
// constructor parameter of a different bean
final @Qualifier("fooConfig") Baz myConfig
If the above is true, then where do we use @Qualifier (with @Bean or @Component) instead of giving the bean a name as shown below?
@Bean
@Qualifier("fooConfig")
public Baz method1(){
}
@Bean
@Qualifier("barConfig")
public Baz method2(){
}
// constructor parameter of a different bean
final @Qualifier("fooConfig") Baz myConfig