Results 1 to 2 of 2

Thread: Annotation for injecting array

  1. #1
    Join Date
    Sep 2006
    Posts
    26

    Question 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?

    thanks,
    Lino

  2. #2
    Join Date
    Sep 2012
    Location
    Czech Republic
    Posts
    39

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •