如何在构造函数中执行以下等效操作,是否可以通过Java代码?
//non DI code
PriorityQueue<Object> queue = new PriorityQueue<Object>(10,
Comparator.comparing(Object::getOrder)
.thenComparing(Object::getDate));
我想将它注入到下面的构造函数中
@Autowired
public CustomPriorityQueue(PriorityQueue<Object> queue)
{
this.queue = queue;
}
答案 0 :(得分:0)
确实我在@Configuration类中需要一个@Bean方法
@SpringBootApplication
@ComponentScan
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
@Primary
public PriorityQueue<WorkOrder> priorityQueue() {
PriorityQueue<WorkOrder> queue = new PriorityQueue<WorkOrder>(10,
Comparator.comparing(WorkOrder::getRank).thenComparing(
WorkOrder::getDatetime));
return queue;
}
}