Description
Roman Pichlík opened SPR-5574 and commented
Let suppose that there are beans of a given type T and these beans are marked by interface Ordered or annotation Order. It does make really sense to preserve their order according to Ordered/Order marker if they are collected. See following code for illustration.
@Component
@Order
(value=1)
public class BusinessServiceA implements BusinessService{}
@Component
@Order
(value=2)
public class BusinessServiceB implements BusinessService{}
@Component
public class ServiceRegistry {
@Autowired
public List<BusinessService> services;
}
assertThat(services.get(0).getClass(), is(BusinessServiceA.class));
assertThat(services.get(1).getClass(), is(BusinessServiceB.class));
Issue Links:
- Allow to define autowired collections and array elements order [SPR-6253] #10921 Allow to define autowired collections and array elements order ("is duplicated by")
- Document common use cases for @Order vs @Priority vs @DependsOn [SPR-16213] #20761 Document common use cases for
@Order
vs@Priority
vs@DependsOn
Referenced from: commits 4a9af23
15 votes, 15 watchers