Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
561 views
in Technique[技术] by (71.8m points)

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

How can I include the common rules list in the lists corresponding to normalInvRules and 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...