Announcement Announcement Module
No announcement yet.
Annotation for injecting array Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Annotation for injecting array

    How do I inject an array via annotations while keeping control over the order? In xml I listed the beans that I wanted in the order that I wanted.

    Following this thread on stackoverflow, I've found the following so far:
    * using the @Autowired annotation: injects all implementations of the interface;
    * using the @Autowired + @Qualifier annotation: injects all implementation of the interface with the same qualifier;
    * using the @Resource annotation: spring throws an IllegalStateException.

    None give me control over the order. Does the @javax.inject.Inject annotation allow for ordering?


  • #2
    If you are able to determine the order, you probably know what beans are to be injected. You can create a bean of type list in a xml where you enumerate all beans you need (reference the beans by name).
    Another option is to write a comparator and use it in the setter method right after the list is injected.