In spring framework, if I have one bean defined as scope "protoype" and it is a parent to another bean. Does child bean automatically become prototype?
Example:
<bean id="a" class="..." scope="prototype"/>
<bean id="b" class="..." parent="a"/>
What will be the scope for b?
I believe it will be a singleton since it is the default scope.
The remaining settings are always taken from the child definition: depends on, autowire mode, dependency check, singleton, scope, lazy init.
As specified in doc : 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.
From the Spring reference:
3.6. Bean definition inheritance. The remaining settings will always be taken from the child definition: depends on, autowire mode, dependency check, singleton, scope, lazy init.
Therefore, t will not inherit the parent's scope
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With