Announcement Announcement Module

JavaConfig forum decommissioned in favor of Core Container

As described at

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:

For any questions related to @Configuration classes and @Bean methods in Spring 3.0, please post in the dedicated 'Core Container' forum at
See more
See less
list bean Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • list bean


    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,

  • #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:

        <bean id="foo" class="...">
            <property name="listProperty">
                    <bean class="Abc"/>
                    <bean class="Xyz"/>
    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