If the parent Object is not singleton the childrens are singleton?

孤街醉人 提交于 2019-12-11 01:24:42

问题


I have a Dao which is not Singleton, if other objetcs extend from him, is singleton or not ? code example

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

</bean>

<bean id="childrenDao"
        class="some.dao.extends.parentDao"
        parent="parentDao">
</bean>

the childrenDao is it singleton?


回答1:


Update: Verified through a test, the scope is also inherited from the parent bean and can be overridden by the child. So in this case childrendDao will be a prototype.

This is what is stated in the reference document: http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/beans.html#beans-child-bean-definitions

A child bean definition inherits constructor argument values, property values, and method overrides from the parent, with the option to add new values. Any initialization method, destroy method, and/or static factory method settings that you specify will override the corresponding parent settings.

The remaining settings are always taken from the child definition: depends on, autowire mode, dependency check, singleton, scope, lazy init.




回答2:


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

    scope="prototype">

 </bean>

<bean id="childrenDao"

    class="some.dao.extends.parentDao"

    parent="parentDao">

I this case childrenDao will be singleton. I have tested it because i became qurious when i saw some confusing answers.



来源:https://stackoverflow.com/questions/11532371/if-the-parent-object-is-not-singleton-the-childrens-are-singleton

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!