Announcement Announcement Module
Collapse
No announcement yet.
Injecting a list of beans in Spring IoC in contrast to CDI Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Injecting a list of beans in Spring IoC in contrast to CDI

    Hi,

    just a little question about the DI handling in Spring IoC. I used CDI for a while so
    I found this little difference between these two frameworks. CDI will inject all instances of an interfaces only if the implementation is not annotated with a specific qualifier. Let me show you in code

    Code:
    /* CDI */
    @Inject
    Instance<MyService> myServices; // This container will contain all instances of MyService which are not annotated with any qualifier
    Code:
    @Inject
    @Any
    Instance<MyService> myServices; // This container will contain all instances of MyService regardless any qualifications
    Code:
    /* Spring IoC */
    @Autowired
    List<MyService> myServices; // This container will contain all instances of MyService regardless any qualifications
    And that's the point. This is very problematically in some situations. If somebody creates a new instance of MyService it will interfere my code and I can't do anything about it except modifying the injection point better say the code using the container. Is there any way to setup Spring IoC so it'll behave like CDI at this point? Thanks in advance.

    Sascha

  • #2
    Nobody? It can't be done with Spring would be a valid answer.

    Comment

    Working...
    X