PDA

View Full Version : Bean config for java.util.ArrayList



teknosalsero
Sep 28th, 2004, 02:48 PM
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...



<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

Alef Arendsen
Sep 28th, 2004, 03:33 PM
Can anyone help me with this?

Yes of course ;-)

http://www.springframework.org/docs/api/org/springframework/beans/factory/config/ListFactoryBean.html



<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>

gpoirier
Sep 28th, 2004, 03:42 PM
See:
http://forum.springframework.org/showthread.php?t=10144

teknosalsero
Sep 28th, 2004, 04:03 PM
Hi Alef,

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

Best regards,

MDS

laran
Sep 28th, 2010, 01:12 PM
This doesn't seem to be working properly for me. I'm using 3.0.


<bean id="jaxb2MarshallerContextPaths" class="org.springframework.beans.factory.config.ListFacto ryBean">
<property name="sourceList">
<list value-type="java.lang.String">
<value>com.foo.manager.schema</value>
<value>com.foo.jaxb.filtertemplate</value>
</list>
</property>
</bean>




@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?