Results 1 to 4 of 4

Thread: newbie question : how to define a bean of type List ?

  1. #1

    Question newbie question : how to define a bean of type List ?

    Hi,

    this is surely a stupid question but I do not find its answer in the docs.

    How can you define a bean which is a <list> ?

    Here is my wished applicationContext :
    Code:
      <bean id="mylist" class="????">
        <value>elem0</value>
        <value>elem1</value>
      </bean>
    
      <bean id="test" class="some.class.with.a.list.attribute">
        <property name="alist"><ref local="mylist" /> </property>
      </bean>
    
      <bean id="test2" class="some.otherclass.with.the.same.list.attribute">
        <property name="alist"><ref local="mylist" /> </property>
      </bean>
    The idea is that I have multiple beans inherited from a class having a list attribute, and that every bean uses EXACTLY the same list so, ATM, I am writing a lots of :
    Code:
      <bean id="test" class="some.class.with.a.list.attribute">
        <property name="alist">
          <list>
            <value>elem0</value>
            <value>elem1</value>
          </list>
      </bean>
    
      <bean id="test2" class="some.otherclass.with.the.same.list.attribute">
        <property name="alist">
          <list>
            <value>elem0</value>
            <value>elem1</value>
          </list>
      </bean>
    
      ...

    thanks for any help,

    regards,
    chris

  2. #2

    Default

    Depend if you use spring 2 or 1.x.

    Check this, it covers both versions :
    http://static.springframework.org/sp....html#d0e28984

  3. #3
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    Take a look at the ListFactoryBean.

    Some example code

    Code:
    <bean id="myList" class="org.springframework.beans.factory.config.ListFactoryBean">
        <property name="sourceList">
            <list>
                <value>elem0</value>
                <value>elem1</value>        
            </list>
        </property>
    </bean>
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  4. #4

    Default

    Thanks for the documentation hints and the example, they perfectly answers my questions.

    regards,
    chris

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •