In my Java spring application, I have
public class BinarySearchImpl {
@Autowired
@Qualifier("Quick")
SortAlgorithem sorter;
Log log=LogFactory.getLog(BinarySearchImpl.class);
public BinarySearchImpl(SortAlgorithem sorter) {
log.info("Binary Search Bean is created");
this.sorter=sorter;
}
SortAlgorithem
is an interface which makes my application loosely coupled:
public interface SortAlgorithem {
public int[] sort(int[] arrayNumbers);
}
And then there are 2 implementations for this interface. One is BubbleSort
:
@Component
@Qualifier("Bubble")
public class BubbleSort implements SortAlgorithem {
Log log=LogFactory.getLog(BubbleSort.class);
public int[] sort(int[] numbers) {
log.info("Bubble sort is called");
return numbers;
}
}
and the other is QuickSort
:
@Component
@Qualifier("Quick")
//@Primary
public class QuickSort implements SortAlgorithem{
Log log= LogFactory.getLog(QuickSort.class);
public int[] sort(int[] numbers) {
log.info("Quick Sort is called");
return numbers;
}
}
At the end, when I call my app it complains with this message:
Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed
I am wondering... Why @Qualifier
annotation does not work?