I have defined an interface IWorker and some implementations of it as WorkerA and WorkerB, both annotated with @Component.
I then autowire them into my app via:
@Autowired
private List<IWorker> workers = new ArrayList<IWorker>();
From what does the order the workers are put into the list depend on?
How can I let additional
WorkerCandWorkerD(also implementations ofIWorker) not annotated with@Componentbe autowired into the same list via myapplicationContext.xml?Is the order of
WorkerCandWorkerDfrom the xml preserved?Is there a rule I can rely on in which order worker A, B, C and D will be put into the list?
If you want to order these dependencies in the List injected by Spring, then use @Order annotation.
来源:https://stackoverflow.com/questions/28012388/bean-order-when-autowired-into-list