有没有办法重新使用< util:list>在春季配置文件? [英] Is there a way to re-use a <util:list> in spring configuration file?
问题描述
我有一堆规则要插入到一组类中,如下所示:
I have a bunch of rules to be injected into a set of classes, something like below:
<bean id="rule1" class="com.vikdor.rules.Rule1" />
<bean id="rule2" class="com.vikdor.rules.Rule2" />
<bean id="rule3" class="com.vikdor.rules.Rule3" />
<bean id="rule4" class="com.vikdor.rules.Rule4" />
<bean id="rule5" class="com.vikdor.rules.Rule5" />
<util:list id="commonRules">
<ref bean="rule1" />
<ref bean="rule3" />
<ref bean="rule5" />
</util:list>
<util:list id="normalInvRules">
<!-- Include common rules -->
<ref bean="rule4" />
</util:list>
<util:list id="prepaidInvRules">
<!-- Include common rules -->
<ref bean="rule2" />
</util:list>
如何在与 normalInvRules
和 prepaidInvRules
相对应的列表中包括通用规则列表?
How can I include the common rules list in the lists corresponding to normalInvRules
and prepaidInvRules
?
规则的数量(例如rule1,rule2等)更多,而组的数量(normalInvRules,prepaidInvRules等)也更多.因此,我想知道是否有一种方法可以避免重复通用规则,而仅列出特定规则并包括对通用列表的引用.
The number of rules (e.g. rule1, rule2 etc.,) are more and the number groups (normalInvRules, prepaidInvRules etc.,) are also more. So, I am wondering if there is a way to avoid repeating the common rules and just list only the specific ones and include the reference to the common list.
推荐答案
有一个名为集合合并"的功能可以完全做到这一点.请参阅第3.3.3.4.1节. Spring文档中的集合合并"或我针对此主题撰写的 2008博客文章(带有示例).
There is a feature called 'collection merging' that does exactly this. See section 3.3.3.4.1. "Collection merging" in the Spring documentation or the 2008 blog post (with an example) that I wrote on the subject.
这篇关于有没有办法重新使用< util:list>在春季配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!