首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

bean承继属性

2012-10-08 
bean继承属性In Java, children classes share a common base type that is determined by theirparent be

bean继承属性
In Java, children classes share a common base type that is determined by their
parent bean. This means that there’s no way in Java for children classes to extend
a common type to inherit properties and/or methods but not to inherit the common
parent.
In Spring, however, sub-beans do not have to share a common parent type.
Two <bean>s with completely different values in their class attributes can still
share a common set of properties that are inherited from a parent bean.
Consider the following abstract parent <bean> declaration:
<bean id="basePerformer" abstract="true">
<property name="song" value="Somewhere Over the Rainbow" />
</bean>
instrument=saxophone
song="Jingle Bells"
baseSaxophonist:Instrumentalist
kenny david
song="Mary had a..."
frank
The frank bean overrides
the song property
Figure 3.3 The frank bean inherits from the baseSaxophonist bean, but
overrides the song property.
78 CHAPTER 3
Advanced bean wiring
This basePerformer bean declares the common song property that our two performers
will share. But notice that it doesn’t have a class attribute set. That’s
okay, because each child bean will determine its own type with its own class
attribute. The new declarations of taylor and stevie are as follows:
<bean id="taylor"
/>
<bean id="stevie"
ref="guitar" />
</bean>
Notice that these beans use both the class attribute and the parent attribute
alongside each other.

热点排行