I am new to spring and spring boot, so hopefully it is not a silly question.
I have an interface with several implementations. Implementations are annotated with @Component("NameOfImpl")
.
My goal is to autowire a bean with selected implementation. In a normal case I can do it with @Autowired @Qualifier("NameOfImpl")
, but my Problem is I want to select an Implementation in a method like:
public void doSomethingMethod(){
for(String line: configFile){
String[] values = line.split(";");
if (values[0].equals("A")) {
//here I want to select an bean implementation
}
else if (values[0].equals("B")) {
//here I want to select another bean implementation
}
}
bean.doSomething();
}
How can I achieve that? What do you suggest? Thank you!