Issue
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
WorkerC
andWorkerD
(also implementations ofIWorker
) not annotated with@Component
be autowired into the same list via myapplicationContext.xml
?Is the order of
WorkerC
andWorkerD
from 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?
Solution
If you want to order these dependencies in the List injected by Spring, then use @Order annotation.
Answered By - Rafal G.
Answer Checked By - Robin (JavaFixing Admin)