osdamv
osdamv

Reputation: 3583

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

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?

Upvotes: 2

Views: 2387

Answers (2)

Anoop Singhal
Anoop Singhal

Reputation: 43

 <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.

Upvotes: 0

Biju Kunjummen
Biju Kunjummen

Reputation: 49935

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.

Upvotes: 4

Related Questions