BubbleSort.java 该类实现SortAlgorithm接口
package com.prakash.Spring.Example;
import org.springframework.stereotype.Component;
@Component
@Qualifier("bubbleSort")
public class BubbleSort implements SortAlgorithm {
public void sort() {
System.out.println("Sort from Bubble Sort");
}
}
Run Code Online (Sandbox Code Playgroud)
QuickSort.java 该类实现了SortAlgorithm接口包com.prakash.Spring.Example;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
@Component
@Qualifier("quickSort")
public class QuickSort implements SortAlgorithm {
@Override
public void sort() {
System.out.println("Sort from Quick Sort");
}
}
Run Code Online (Sandbox Code Playgroud)
排序算法.java
package com.prakash.Spring.Example;
public interface SortAlgorithm {
void sort();
}
Run Code Online (Sandbox Code Playgroud)
BinarySearch.java 在这个类中,我想使用 fastSort bean 作为我的组件。
package com.prakash.Spring.Example;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
@Component
public class BinarySearch {
@Autowired …Run Code Online (Sandbox Code Playgroud)