Announcement Announcement Module
No announcement yet.
Dependency Injection btw Bean in a List Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dependency Injection btw Bean in a List

    I did some google, but I couldnt find any case similar like my case. So I post my case here.

    I was trying to do dependency injection between bean in a list as below:

    <property name="fruits">
            <bean id="apple" class="test.Apple"/>
            <bean id="orange" class="test.Orange">
                <property value="apple" ref="apple"/>
    When I try to start my apps, I get error/exception as below:
    org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'apple' is defined
    This error is saying that, when Spring initializing 'orange' bean, Spring failed to find 'apple' bean when trying to inject 'apple' into 'orange'.

    My Question is:
    1. Can i make injection between beans within a list?
    2. If i cant make injection between beans within a list, why? Is that injection like this is offend with the way spring load and init beans?

    Thanks for viewing + replies. Thank you!

  • #2

    "An inner bean definition does not require a defined id or name; the container ignores these values. It also ignores the scope flag. Inner beans are always anonymous and they are always scoped as prototypes. It is not possible to inject inner beans into collaborating beans other than into the enclosing bean."