Results 1 to 4 of 4

Thread: Does the XML config support List as a standalone element?

Hybrid View

  1. #1
    Join Date
    Sep 2004
    Posts
    2

    Default 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. #2
    Join Date
    Aug 2004
    Location
    u.s.a
    Posts
    399

    Default

    Can't you just use a List as a bean?

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

  3. #3

    Default

    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>

  4. #4
    Join Date
    Sep 2004
    Posts
    2

    Default

    thanks

Similar Threads

  1. Replies: 3
    Last Post: Mar 10th, 2007, 02:55 PM
  2. Replies: 1
    Last Post: Jul 28th, 2005, 05:08 PM
  3. Odd behaviour when injecting TransactionTemplate
    By damon311 in forum Container
    Replies: 3
    Last Post: Jul 23rd, 2005, 11:21 AM
  4. avoiding duplication when using list element
    By markjvickers in forum Container
    Replies: 6
    Last Post: Jun 20th, 2005, 07:49 AM
  5. Replies: 12
    Last Post: Sep 25th, 2004, 04:24 PM

Posting Permissions

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