如何在spring配置中扩展列表 [英] how to extend a list in spring config
本文介绍了如何在spring配置中扩展列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经定义了一些常用"值.如何通过附加值将公用列表扩展到各种新bean?
I have defined a with some "common" values. How can I extend the common list by additional values to various new beans?
<util:list id="myCommonList" list-class="java.util.LinkedList">
<bean .../>
<bean .../>
<bean .../>
<bean .../>
</util:list>
<bean id="extension" parent="myCommonList">
<bean ref="additionalValue"/>
</bean>
这会覆盖列表还是扩展列表?
Will this overwrite the list or extend it?
推荐答案
您可以执行此操作,但不使用<util:list>
,这只是一种方便的语法.容器确实提供了集合合并"功能,但是您必须使用旧"样式:
You can do it, but not using <util:list>
, which is just a convenience syntax. The container does provide a "collection merging" function, but you have to use the "old" style:
<bean id="parent" class="org.springframework.beans.factory.config.ListFactoryBean">
<property name="sourceList">
<list>
<value>X</value>
</list>
</property>
</bean>
<bean id="child" parent="parent" class="org.springframework.beans.factory.config.ListFactoryBean">
<property name="sourceList">
<list merge="true">
<value>Y</value>
</list>
</property>
</bean>
这篇关于如何在spring配置中扩展列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文