【Spring学习10】依赖配置:bean的父子继承
发布时间:2020-12-14 01:38:23 所属栏目:百科 来源:网络整理
导读:Spring Bean的父子继承主要是为了统一定义Spring Bean的公共属性、作业范围scope,并避免了冗余和修改的繁琐。 beans bean id = "notify" class = "twm.spring.start.NotifyServiceByCellPhoneImpl" / bean id = "parent" abstract = "true" class = "exampl
Spring Bean的父子继承主要是为了统一定义Spring Bean的公共属性、作业范围scope,并避免了冗余和修改的繁琐。 <beans>
<bean id="notify" class="twm.spring.start.NotifyServiceByCellPhoneImpl" />
<bean id="parent" abstract="true" class="example.ComplexObject">
<property name="notifyservice" ref="notify"/>
<property name="adminEmails">
<props>
<prop key="administrator">administrator@example.com</prop>
<prop key="support">support@example.com</prop>
</props>
</property>
</bean>
<bean id="child" parent="parent">
<property name="adminEmails">
<props merge="true">
<prop key="sales">sales@example.com</prop>
<prop key="support">support@example.co.uk</prop>
</props>
</property>
</bean>
<beans>
可以看到child bean无需声明class,它用parent声明了父对象,这样就继承了父对象的class声明,以及notifyservice属性值,adminEmails的值也会从父对象继承并合并。 如果父对象声明了属性 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |