Type: New Feature
Affects Version/s: 3.0 RC1
Fix Version/s: None
Last commented by a User:false
However, there is a possible use-case that a user wants to define particular order for autowired collection/array. It looks obvious in the case of autowiring typed lists (the client may want to preserve particular order for the list elements) but the same idea may be spread easily to sets/maps/arrays.
I suggest the following rules to be used during examining the order for two elements:
- if both classes of compared object are marked by Ordered the one with lower value is considered to be less than another;
- if class of one element is marked by Ordered and class of another is not marked by Ordered the former is considered to be less than the later;
- if both classes of compared elements are not marked by Ordered but implement Comparable with consisting type parameter they are compared via Comparable#compareTo(Object);
Please note that the rules above may be applied to all elements of autowired collection/array in order to define particular for them.
That feature may be optional and defaults to perform ordering. It seems that most natural to allow to define it via additional method of @Autowired annotation.
So, it can be implemented easily via minor AutowiredAnnotationBeanPostProcessor modification - the argument to be injected is just sorted if necessary.
Attached archive contains either feature implementation (classes from 'org.springframework.beans.factory.annotation' package) or usage example (classes from 'com.spring.example' package and its subpackages).