Spring入门学习——bean属性配置(二)

来源:互联网 发布:c语言的库函数 编辑:程序博客网 时间:2024/06/13 20:22
合并父Bean集合
如果用继承定义Bean,子Bean的集合可以通过设置Merge属性为True与父Bean合并
对于<list>集合,子元素将附加在父元素后保持顺序。生成的序列后缀将有ABAC

<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="baseSequenceGenerator" class="com.cgy.springrecipes.sequence.SequenceGenerator"
p:prefix="30" p:suffix="B" p:initial="101000">
<property name="suffixes">
<list>
<value>A</value>
<value>B</value>
</list>
</property>
</bean>
<bean id="sequenceGenerator" parent="baseSequenceGenerator">
<property name="suffixes">
<list merge="true">
<value>A</value>
<value>C</value>
</list>
</property>
</bean>
</beans>

对于<set>或<map>集合,如果值相同,子元素将会覆盖父元素。生成的序列后缀将有ABC

<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="baseSequenceGenerator" class="com.cgy.springrecipes.sequence.SequenceGenerator"
p:prefix="30" p:suffix="B" p:initial="101000">
<property name="suffixes">
<set>
<value>A</value>
<value>B</value>
</set>
</property>
</bean>
<bean id="sequenceGenerator" parent="baseSequenceGenerator">
<property name="suffixes">
<set merge="true">
<value>A</value>
<value>C</value>
</set>
</property>
</bean>
</beans>


0 0
原创粉丝点击