I've configured in Spring listA (see below). It would开发者_开发知识库 be nice to have another one that contains all values from listA and expand it.
<bean id="listA" class="java.util.ArrayList">
<constructor-arg>
<list>
<value>a</value>
<value>b</value>
<value>...</value>
<value>z</value>
</list>
</constructor-arg>
</bean>
How to rewrite in Spring such Java code?
List listB = new ArrayList(listA);
listB.add("A");
...
listB.add("Z");
You can use collection merging:
<bean id="listA" class="java.util.ArrayList">
<constructor-arg index="0">
<list>
<value>a</value>
<value>b</value>
<value>...</value>
<value>z</value>
</list>
</constructor-arg>
</bean>
<bean id="listB" parent="listA">
<constructor-arg index="0">
<list merge="true">
<value>A</value>
<value>...</value>
<value>Z</value>
</list>
</constructor-arg>
</bean>
精彩评论