How the <list> tag works in spring
I have Collection tools; in my SomeClass.java, and I declare in my temp.xml bean of the class SomeClass.java. In xml, I add two string objects to the collection.
My question is: Collection is an interface, so I can't create it, and List is also an interface, so I don't think we can do
Collection<String> someCollection = new List<String>();
I would like to know how java code works when we use the list tag in an XML file. So the objects are stored in a linked list or in an arraylist or in some kind of list?
+5
2 answers
ApplicationContext. , , List. Accoding :
. bean ListFactoryBean, , . bean - , , list-class , List . list-class , ApplicationContext .
<util:list id="messageUtilList">
<ref bean="stringMessage01"/>
<ref bean="stringMessage02"/>
<value>Spring is fun to learn.</value>
</util:list>
<util:list id="messageUtilLinkedList"
list-class="java.util.LinkedList">
<ref bean="stringMessage01"/>
<ref bean="stringMessage02"/>
<value>Spring is fun to learn.</value>
</util:list>
ListFactoryBean, , ArrayList - , , . , :
if (this.targetListClass != null) {
result = (List) BeanUtils.instantiateClass(this.targetListClass);
}
else {
result = new ArrayList(this.sourceList.size());
}
+11