I have two implementations for a single interface and I segregated them using @Qualifier("IMP1") and @Qualifier("IMP2") and this is the case for most of the interfaces in my application.
And the requirement is autowire "IMP2" of an interface if available or autowire "IMP1".
As of now, I'm handling like
@Autowired(required = false)
@Qualifier("IMP1")
HelloService imp1Service;
@Autowired(required = false)
@Qualifier("IMP2")
HelloService imp2Service;
@GetMapping("/hello")
public String hello() {
if(l1Service != null){
return imp2Service.getString();
} else {
return imp1Service.getString();
}
}
But this is not an elegant way as I've to check for all interfaces in the same way. how to do this