Announcement Announcement Module
Collapse
No announcement yet.
Does the XML config support List as a standalone element? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Does the XML config support List as a standalone element?

    I am trying to create a list with elements and have other beans reference this list. It seems the only way to do this is something like the following

    <bean id="attributeList" class="org.springframework.beans.factory.config.Me thodInvokingFactoryBean">
    <property name="targetObject"><ref local="characterPrototype"/></property>
    <property name="targetMethod"><value>getAttributes</value></property>
    </bean>


    <bean id="call00" class="org.springframework.beans.factory.config.Me thodInvokingFactoryBean">
    <property name="targetObject"><ref local="pdPrototype"/></property>
    <property name="targetMethod"><value>setAttributeList</value></property>
    <property name="arguments">
    <list>
    <ref bean="attributeList"/>
    </list>
    </property>
    </bean>

    Is there a mechanism to make a list a top level element in the application context?
    <list id="attributeList>
    <ref bean="..."/>
    </list>

    <bean ..>
    <property name="attributeList">
    <ref bean="attributeList" />
    </property>
    </bean>

    In general can any of the bean element tags (List, Set, Map, and Properties) be used at the top level?

    thanks

  • #2
    Can't you just use a List as a bean?

    <bean id="myList"
    class="java.util.ArrayList">
    <property name .......
    <list>
    stuff....
    </list>
    </bean>

    Comment


    • #3
      There's two ways you can do that:

      Code:
        <bean id="list1" class="org.springframework.beans.factory.config.ListFactoryBean">
          <property name="sourceList">
            <list>
              <value>123</value>
              <value>456</value>
              <value>789</value>
            </list>
          </property>
        </bean>
      
        <bean id="list2" class="java.util.LinkedList">
          <constructor-arg>
            <list>
              <value>123</value>
              <value>456</value>
              <value>789</value>
            </list>      
          </constructor-arg>
        </bean>

      Comment


      • #4
        thanks

        Comment

        Working...
        X