Another option is to use JavaConfig. Assuming that all stages are already registered as spring beans you just have to:
@Autowired
private List<Stage> stages;
and spring will automatically inject them into this list. If you need to preserve order (upper solution doesn't do that) you can do it in that way:
@Configuration
public class MyConfiguration {
@Autowired
private Stage1 stage1;
@Autowired
private Stage2 stage2;
@Bean
public List<Stage> stages() {
return Lists.newArrayList(stage1, stage2);
}
}
The other solution to preserve order is use a @Order
annotation on beans. Then list will contain beans ordered by ascending annotation value.
@Bean
@Order(1)
public Stage stage1() {
return new Stage1();
}
@Bean
@Order(2)
public Stage stage2() {
return new Stage2();
}