Which is the best way to pass/use a @Bean
type present in the same configuration class to another @Bean
?
For example if I have the current situation:
@Configuration
public ConfigurationSample {
@Bean("first")
public CustomType beanA(){
}
@Bean("four")
public CustomType beanD(){
}
@Bean("second")
public OtherCustomType beanB(@Qualifier("first") CustomType bean){
//Use bean
}
@Bean("third")
public OtherCustomType beanC(){
CustomType bean = beanA();
....
....
}
}
Should I use the @Qualifier
annotation or i can directly call the bean or it's equivalent and why?
EDIT
Reading responses I added beanD()
missing before (sorry!) to make more clear the need of @Qualifier
annotation.
@Qualifier
or just call the method frombeanb()
method. Either will work.