Does the baby bean automatically become a prototype if the parent bean is defined as a prototype

In the spring framework, if I have one bean defined as a "protoype" scope, and it is the parent for another bean. Will a baby bean automatically become a prototype?

Example:

<bean id="a" class="..." scope="prototype"/> <bean id="b" class="..." parent="a"/> 

What will be the area for b?

+5
source share
5 answers

I believe this will be singleton, as this is the default area.

The rest of the settings are always taken from the definition of the child : it depends on the mode of auto-device, dependency checking, singleton, scope, lazy init.

+5
source

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

The definition of a child bean inherits the values โ€‹โ€‹of the constructor argument, the value property and method overrides the parent element, with the ability to add new values. Any initialization method, destruction method, and / or static factory Method parameters that you specify override the corresponding parent settings.

The rest of the settings are always taken from the definition of the child: it depends on the auto-device mode, dependency checking, singleton, scope, lazy initialization.

+3
source

From spring link:

3.6. Inheritance of definition of a bin. The remaining settings will always be taken from the child definition: depends on, auto-wiring mode, dependency checking, singleton, scope, lazy init.

Therefore, t will not inherit the parent scope.

+2
source

In the white paper, spring subtype will inherit all attributes of the parent, the definition of the attribute subclass will override the attributes of the parent class

If you do not specify a scope, it will be inherited from the parent

0
source

The baby bean will not receive parental coverage.

0
source

Source: https://habr.com/ru/post/1209278/


All Articles