Results 1 to 5 of 5

Thread: Bean config for java.util.ArrayList

  1. #1

    Default Bean config for java.util.ArrayList

    Is there a way to populate a bean that is of class ArrayList?
    I simply want an ArrayList populated with some objects,
    let's call them "x", "y", "z".

    I tried the following, but with no success...


    Code:
    <bean id="entriesList" class="java.util.ArrayList">
         <ref bean="x"/>
         <ref bean="y"/>
         <ref bean="z"/>
    </bean>
    
    <bean id="x" class="... ..."/> etc.
    Can anyone help me with this? Thanks in advance,

    MDS

  2. #2
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default Re: Bean config for java.util.ArrayList

    Quote Originally Posted by teknosalsero
    Can anyone help me with this?
    Yes of course ;-)

    http://www.springframework.org/docs/...ctoryBean.html

    Code:
    <bean id="list" class="org.springframework.beans.factory/config/ListFactoryBean">
      <property name="sourceList">
        <list>
          <ref bean="x"/>
          <ref bean="y"/>
        </list>
      </property>
      <!-- this property is optional, defaults to ArrayList -->
      <property name="targetList"><value>java.util.LinkedList</value></property>
    </bean>
    <edit>There are factory beans for Sets and HashMaps as well by the way as well as one for Properties.</edit>

  3. #3

    Default

    Last edited by robyn; May 14th, 2006 at 04:47 PM.

  4. #4

    Default

    Hi Alef,

    Thanks for the quick reply. It looks good and
    I will use it in my code.

    Best regards,

    MDS

  5. #5
    Join Date
    Oct 2009
    Posts
    18

    Default

    This doesn't seem to be working properly for me. I'm using 3.0.

    Code:
    	<bean id="jaxb2MarshallerContextPaths" class="org.springframework.beans.factory.config.ListFactoryBean">
    		<property name="sourceList">
    			<list value-type="java.lang.String">
    				<value>com.foo.manager.schema</value>
    				<value>com.foo.jaxb.filtertemplate</value>
    			</list>
    		</property>
    	</bean>
    Code:
    @Component("jaxb2Marshaller")
    public class FMJaxb2Marshaller extends Jaxb2Marshaller {
    	@Override
    	@Resource(name="jaxb2MarshallerContextPaths")
    	public void setContextPaths(String... contextPaths) {
    		super.setContextPaths(contextPaths);
    	}
    }
    But IntelliJ tells me that this is invalid because the argument type is String. Have I done something wrong? Or is IntelliJ wrong?

Similar Threads

  1. Order of Bean definitions matters?
    By cfuser in forum Container
    Replies: 2
    Last Post: Oct 21st, 2005, 10:29 AM
  2. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  3. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  4. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  5. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 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
  •