Announcement Announcement Module
Collapse

JavaConfig forum decommissioned in favor of Core Container

As described at

http://static.springsource.org/sprin...fig/README.TXT

key features of the Spring JavaConfig project have been migrated into the core Spring Framework as of version 3.0.

Please see the Spring 3.0 documentation on @Configuration and @Bean support:

http://static.springsource.org/sprin...tml#beans-java

For any questions related to @Configuration classes and @Bean methods in Spring 3.0, please post in the dedicated 'Core Container' forum at

http://forum.springsource.org/forumdisplay.php?f=26
See more
See less
list bean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • list bean

    Hi,

    This is partially a general Spring question

    I want a @Bean method to return a list of beans (so that the container configures each, in particular, if they are a XxxAwareBean, call the right methods etc.). How can I do that (will returning a ListBeanFactory work?)

    Thank you,
    Ittay

  • #2
    Hi Ittay,

    The elements of a List won't be managed by the spring container unless the elements are themselves @Beans.

    You asked about ListBeanFactory? I assume you meant ListFactoryBean. This class is used under the covers when dealing with the <list> element in Spring XML:

    Code:
    <beans>
        <bean id="foo" class="...">
            <property name="listProperty">
                <list>
                    <bean class="Abc"/>
                    <bean class="Xyz"/>
                </list>
            </property>
        </bean>
    </beans>
    In the example above, the beans of type Abc and Xyz are 'inner beans' and are thus managed by the Spring container.

    The most straightforward thing to do to mimic this in JavaConfig is to create multiple @Bean methods: one for your list, and one for each of your list elements. When creating the list bean, just populate it through method calls to the other @Bean methods.

    You could roll your own, more sophisticated support for this by proxying the collection and allowing the collection to interact with the container, but this is probably beyond what you're looking for.

    - C

    Comment

    Working...
    X