Announcement Announcement Module
Collapse
No announcement yet.
Dependency Injection btw Bean in a List Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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:

    Code:
    ...
    <property name="fruits">
        <list>
            <bean id="apple" class="test.Apple"/>
            <bean id="orange" class="test.Orange">
                <property value="apple" ref="apple"/>
            </bean>
        </list>
    </property>
    ...
    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
    http://static.springsource.org/sprin...ns-inner-beans

    Especially:
    "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."

    Comment

    Working...
    X