So, I am trying to learn my way with Spring Boot. I tried @Qualifier and @Autowired but it gives me the following error:
Parameter 0 of constructor in io.cptpackage.springboot.bootdemo.BinarySearch required a single bean, but 2 were found:
Even tho I have provided the right @Qualifier it doesn't work until one of the dependencies has a @Primary annotation, also the name reference doesn't work I to use @Primary or @Qualifier and you know that I am having the issue with the @Qualifier thing. The code is simple and as following.
@Component
public class BinarySearch {
// Sort, Search, Return the result!
@Autowired
@Qualifier("quick")
Sorter sorter;
public BinarySearch(Sorter sorter) {
super();
this.sorter = sorter;
}
public int search(int[] numbersToSearchIn, int targetNumber) {
sorter.sort(numbersToSearchIn);
return targetNumber;
}
}
The first dependency:
@Component
@Qualifier("bubble")
public class BubbleSort implements Sorter {
@Override
public int[] sort(int[] targetArray) {
System.out.println("Bubble sort!");
return targetArray;
}
}
The second dependency:
@Component
@Qualifier("quick")
public class QuickSort implements Sorter {
@Override
public int[] sort(int[] targetArray) {
System.out.println("Quick Sort!");
return targetArray;
}
}
Also why is autowiring by name isnot working?