如果父对象不是单身,那么孩子们是单身人士吗?

时间:2012-07-17 23:39:19

标签: java spring singleton

我有一个不是Singleton的Dao,其他对象是从他身上延伸出来的,是单身还是不单身?代码示例

<bean id="dao" class="parentDao"
        scope="prototype">

</bean>

<bean id="childrenDao"
        class="some.dao.extends.parentDao"
        parent="parentDao">
</bean>
孩子们是单身吗?

2 个答案:

答案 0 :(得分:4)

更新:通过测试验证,范围也从父bean继承,并且可以被子项覆盖。所以在这种情况下,childrendDao将成为原型。

这是参考文件中所述的内容: http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/beans.html#beans-child-bean-definitions

  

子bean定义继承构造函数参数值property   值和来自父级的方法覆盖,以及要添加的选项   新的价值观。任何初始化方法,destroy方法和/或静态   您指定的工厂方法设置将覆盖   相应的父设置。

     

其余设置始终取自子定义:   取决于,autowire模式,依赖性检查,单身,范围,懒惰   初始化。

答案 1 :(得分:0)

 <bean id="dao" class="parentDao"

    scope="prototype">

 </bean>

<bean id="childrenDao"

    class="some.dao.extends.parentDao"

    parent="parentDao">

我在这种情况下,孩子们将是单身人士。我测试了它,因为当我看到一些令人困惑的答案时我变得很虚伪。