-
Notifications
You must be signed in to change notification settings - Fork 0
Exceptions
Yash edited this page Aug 10, 2018
·
1 revision
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
public interface SortAlgorithem {
public int[] sort(int[] arrayNumbers);
}
@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;
}
}
@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;
}
}Solution:
public class BinarySearchImpl {
/*@Autowired
@Qualifier("Quick")
SortAlgorithem sorter;*/
private SortAlgorithm sorter;
@Autowired
public BinarySearchImpl(@Qualifier("quick") SortAlgorithm sorter) {
this.sorter = sorter;
}
}Spring Boot is a project that is built on the top of the Spring Framework. It provides an easier and faster way to set up, configure, and run both simple and web-based applications. It is a Spring module that provides the RAD (Rapid Application Development) feature to the Spring Framework.