开发者

Why is this JavaBean XML code written like this?

In the source code for a project I'm working on, there are many definitions of java beans of the form:

  <bean id="BeanName" parent="BeanName-paren开发者_StackOverflow社区tBean"/>

  <bean id="BeanName-parentBean" abstract="true" parent="RealParentBean"> 
    <property name="foo" value="bar"/>
    <property name="herp" value="derp"/>
  </bean>

I don't understand the difference between this and the more succinct:

  <bean id="BeanName" parent="RealParentBean"> 
    <property name="foo" value="bar"/>
    <property name="herp" value="derp"/>
  </bean>

Are there stylistic or practical reasons for this?


One thing, having the parent bean written in it's own bean definition makes it easier to create other beans that refer to the parent bean without a bunch of copy/pasting.

i.e.

<bean id="BeanName" parent="BeanName-parentBean"/>
<bean id="BeanName2" parent="BeanName-parentBean"/>
<bean id="BeanName3" parent="BeanName-parentBean"/>

  <bean id="BeanName-parentBean" abstract="true" parent="RealParentBean"> 
    <property name="foo" value="bar"/>
    <property name="herp" value="derp"/>
  </bean>

V.S.

  <bean id="BeanName" parent="RealParentBean"> 
    <property name="foo" value="bar"/>
    <property name="herp" value="derp"/>
  </bean>
  <bean id="BeanName2" parent="RealParentBean"> 
    <property name="foo" value="bar"/>
    <property name="herp" value="derp"/>
  </bean>
  <bean id="BeanName3" parent="RealParentBean"> 
    <property name="foo" value="bar"/>
    <property name="herp" value="derp"/>
  </bean>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜