Class RootBeanDefinition
java.lang.Object
org.springframework.core.AttributeAccessorSupport
org.springframework.beans.BeanMetadataAttributeAccessor
org.springframework.beans.factory.support.AbstractBeanDefinition
org.springframework.beans.factory.support.RootBeanDefinition
- All Implemented Interfaces:
Serializable
,Cloneable
,BeanMetadataElement
,BeanDefinition
,AttributeAccessor
A root bean definition represents the merged bean definition that backs
a specific bean in a Spring BeanFactory at runtime. It might have been created
from multiple original bean definitions that inherit from each other,
typically registered as
GenericBeanDefinitions
.
A root bean definition is essentially the 'unified' bean definition view at runtime.
Root bean definitions may also be used for registering individual bean definitions
in the configuration phase. However, since Spring 2.5, the preferred way to register
bean definitions programmatically is the GenericBeanDefinition
class.
GenericBeanDefinition has the advantage that it allows to dynamically define
parent dependencies, not 'hard-coding' the role as a root bean definition.
- Author:
- Rod Johnson, Juergen Hoeller
- See Also:
-
Field Summary
Fields inherited from class org.springframework.beans.factory.support.AbstractBeanDefinition
AUTOWIRE_AUTODETECT, AUTOWIRE_BY_NAME, AUTOWIRE_BY_TYPE, AUTOWIRE_CONSTRUCTOR, AUTOWIRE_NO, DEPENDENCY_CHECK_ALL, DEPENDENCY_CHECK_NONE, DEPENDENCY_CHECK_OBJECTS, DEPENDENCY_CHECK_SIMPLE, INFER_METHOD, SCOPE_DEFAULT
Fields inherited from interface org.springframework.beans.factory.config.BeanDefinition
ROLE_APPLICATION, ROLE_INFRASTRUCTURE, ROLE_SUPPORT, SCOPE_PROTOTYPE, SCOPE_SINGLETON
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new RootBeanDefinition, to be configured through its bean properties and configuration methods.RootBeanDefinition
(Class<?> beanClass) Create a new RootBeanDefinition for a singleton.RootBeanDefinition
(Class<?> beanClass, int autowireMode, boolean dependencyCheck) Create a new RootBeanDefinition for a singleton, using the given autowire mode.RootBeanDefinition
(Class<?> beanClass, ConstructorArgumentValues cargs, MutablePropertyValues pvs) Create a new RootBeanDefinition for a singleton, providing constructor arguments and property values.RootBeanDefinition
(Class<T> beanClass, String scope, Supplier<T> instanceSupplier) Create a new RootBeanDefinition for a scoped bean, constructing each instance through calling the given supplier (possibly a lambda or method reference).RootBeanDefinition
(Class<T> beanClass, Supplier<T> instanceSupplier) Create a new RootBeanDefinition for a singleton bean, constructing each instance through calling the given supplier (possibly a lambda or method reference).RootBeanDefinition
(String beanClassName) Create a new RootBeanDefinition for a singleton, providing constructor arguments and property values.RootBeanDefinition
(String beanClassName, ConstructorArgumentValues cargs, MutablePropertyValues pvs) Create a new RootBeanDefinition for a singleton, providing constructor arguments and property values.RootBeanDefinition
(RootBeanDefinition original) Create a new RootBeanDefinition as deep copy of the given bean definition. -
Method Summary
Modifier and TypeMethodDescriptionClone this bean definition.boolean
Return the target definition that is being decorated by this bean definition, if any.Return all externally managed configuration methods and fields (as an immutable Set).Return all externally managed destruction methods (as an immutable Set).Return all externally managed initialization methods (as an immutable Set).Return the name of the parent definition of this bean definition, if any.Constructor<?>[]
Determine preferred constructors to use for default construction, if any.Return theAnnotatedElement
defining qualifiers, if any.Return aResolvableType
for this bean definition, either from runtime-cached type information or from configuration-timesetTargetType(ResolvableType)
orAbstractBeanDefinition.setBeanClass(Class)
, also considering resolved factory method definitions.Return the resolved factory method as a Java Method object, if available.Class<?>
Return the target type of this bean definition, if known (either specified in advance or resolved on first instantiation).boolean
isExternallyManagedConfigMember
(Member configMember) Check whether the given method or field is an externally managed configuration member.boolean
isExternallyManagedDestroyMethod
(String destroyMethod) Check whether the given method name indicates an externally managed destruction method.boolean
isExternallyManagedInitMethod
(String initMethod) Check whether the given method name indicates an externally managed initialization method.boolean
isFactoryMethod
(Method candidate) Check whether the given candidate qualifies as a factory method.void
registerExternallyManagedConfigMember
(Member configMember) Register an externally managed configuration method or field.void
registerExternallyManagedDestroyMethod
(String destroyMethod) Register an externally managed configuration destruction method.void
registerExternallyManagedInitMethod
(String initMethod) Register an externally managed configuration initialization method.void
setDecoratedDefinition
(BeanDefinitionHolder decoratedDefinition) Register a target definition that is being decorated by this bean definition.void
Specify a factory method name that refers to an overloaded method.void
setParentName
(String parentName) Set the name of the parent definition of this bean definition, if any.void
setQualifiedElement
(AnnotatedElement qualifiedElement) Specify theAnnotatedElement
defining qualifiers, to be used instead of the target class or factory method.void
setResolvedFactoryMethod
(Method method) Set a resolved Java Method for the factory method on this bean definition.void
setTargetType
(Class<?> targetType) Specify the target type of this bean definition, if known in advance.void
setTargetType
(ResolvableType targetType) Specify a generics-containing target type of this bean definition, if known in advance.void
Specify a factory method name that refers to a non-overloaded method.toString()
Methods inherited from class org.springframework.beans.factory.support.AbstractBeanDefinition
addQualifier, applyDefaults, clone, copyQualifiersFrom, getAutowireMode, getBeanClass, getBeanClassName, getConstructorArgumentValues, getDependencyCheck, getDependsOn, getDescription, getDestroyMethodName, getFactoryBeanName, getFactoryMethodName, getInitMethodName, getInstanceSupplier, getLazyInit, getMethodOverrides, getOriginatingBeanDefinition, getPropertyValues, getQualifier, getQualifiers, getResolvedAutowireMode, getResource, getResourceDescription, getRole, getScope, hasBeanClass, hasConstructorArgumentValues, hashCode, hasMethodOverrides, hasPropertyValues, hasQualifier, isAbstract, isAutowireCandidate, isEnforceDestroyMethod, isEnforceInitMethod, isLazyInit, isLenientConstructorResolution, isNonPublicAccessAllowed, isPrimary, isPrototype, isSingleton, isSynthetic, overrideFrom, prepareMethodOverride, prepareMethodOverrides, resolveBeanClass, setAbstract, setAutowireCandidate, setAutowireMode, setBeanClass, setBeanClassName, setConstructorArgumentValues, setDependencyCheck, setDependsOn, setDescription, setDestroyMethodName, setEnforceDestroyMethod, setEnforceInitMethod, setFactoryBeanName, setFactoryMethodName, setInitMethodName, setInstanceSupplier, setLazyInit, setLenientConstructorResolution, setMethodOverrides, setNonPublicAccessAllowed, setOriginatingBeanDefinition, setPrimary, setPropertyValues, setResource, setResourceDescription, setRole, setScope, setSynthetic, validate
Methods inherited from class org.springframework.beans.BeanMetadataAttributeAccessor
addMetadataAttribute, getAttribute, getMetadataAttribute, getSource, removeAttribute, setAttribute, setSource
Methods inherited from class org.springframework.core.AttributeAccessorSupport
attributeNames, computeAttribute, copyAttributesFrom, hasAttribute
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.core.AttributeAccessor
attributeNames, computeAttribute, getAttribute, hasAttribute, removeAttribute, setAttribute
Methods inherited from interface org.springframework.beans.BeanMetadataElement
getSource
-
Constructor Details
-
RootBeanDefinition
public RootBeanDefinition()Create a new RootBeanDefinition, to be configured through its bean properties and configuration methods.- See Also:
-
AbstractBeanDefinition.setBeanClass(java.lang.Class<?>)
AbstractBeanDefinition.setScope(java.lang.String)
AbstractBeanDefinition.setConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues)
AbstractBeanDefinition.setPropertyValues(org.springframework.beans.MutablePropertyValues)
-
RootBeanDefinition
Create a new RootBeanDefinition for a singleton.- Parameters:
beanClass
- the class of the bean to instantiate- See Also:
-
RootBeanDefinition
Create a new RootBeanDefinition for a singleton bean, constructing each instance through calling the given supplier (possibly a lambda or method reference).- Parameters:
beanClass
- the class of the bean to instantiateinstanceSupplier
- the supplier to construct a bean instance, as an alternative to a declaratively specified factory method- Since:
- 5.0
- See Also:
-
RootBeanDefinition
public RootBeanDefinition(@Nullable Class<T> beanClass, String scope, @Nullable Supplier<T> instanceSupplier) Create a new RootBeanDefinition for a scoped bean, constructing each instance through calling the given supplier (possibly a lambda or method reference).- Parameters:
beanClass
- the class of the bean to instantiatescope
- the name of the corresponding scopeinstanceSupplier
- the supplier to construct a bean instance, as an alternative to a declaratively specified factory method- Since:
- 5.0
- See Also:
-
RootBeanDefinition
Create a new RootBeanDefinition for a singleton, using the given autowire mode.- Parameters:
beanClass
- the class of the bean to instantiateautowireMode
- by name or type, using the constants in this interfacedependencyCheck
- whether to perform a dependency check for objects (not applicable to autowiring a constructor, thus ignored there)
-
RootBeanDefinition
public RootBeanDefinition(@Nullable Class<?> beanClass, @Nullable ConstructorArgumentValues cargs, @Nullable MutablePropertyValues pvs) Create a new RootBeanDefinition for a singleton, providing constructor arguments and property values.- Parameters:
beanClass
- the class of the bean to instantiatecargs
- the constructor argument values to applypvs
- the property values to apply
-
RootBeanDefinition
Create a new RootBeanDefinition for a singleton, providing constructor arguments and property values.Takes a bean class name to avoid eager loading of the bean class.
- Parameters:
beanClassName
- the name of the class to instantiate
-
RootBeanDefinition
public RootBeanDefinition(String beanClassName, ConstructorArgumentValues cargs, MutablePropertyValues pvs) Create a new RootBeanDefinition for a singleton, providing constructor arguments and property values.Takes a bean class name to avoid eager loading of the bean class.
- Parameters:
beanClassName
- the name of the class to instantiatecargs
- the constructor argument values to applypvs
- the property values to apply
-
RootBeanDefinition
Create a new RootBeanDefinition as deep copy of the given bean definition.- Parameters:
original
- the original bean definition to copy from
-
-
Method Details
-
getParentName
Description copied from interface:BeanDefinition
Return the name of the parent definition of this bean definition, if any. -
setParentName
Description copied from interface:BeanDefinition
Set the name of the parent definition of this bean definition, if any. -
setDecoratedDefinition
Register a target definition that is being decorated by this bean definition. -
getDecoratedDefinition
Return the target definition that is being decorated by this bean definition, if any. -
setQualifiedElement
Specify theAnnotatedElement
defining qualifiers, to be used instead of the target class or factory method.- Since:
- 4.3.3
- See Also:
-
getQualifiedElement
Return theAnnotatedElement
defining qualifiers, if any. Otherwise, the factory method and target class will be checked.- Since:
- 4.3.3
-
setTargetType
Specify a generics-containing target type of this bean definition, if known in advance.- Since:
- 4.3.3
-
setTargetType
Specify the target type of this bean definition, if known in advance.- Since:
- 3.2.2
-
getTargetType
Return the target type of this bean definition, if known (either specified in advance or resolved on first instantiation).- Since:
- 3.2.2
-
getResolvableType
Return aResolvableType
for this bean definition, either from runtime-cached type information or from configuration-timesetTargetType(ResolvableType)
orAbstractBeanDefinition.setBeanClass(Class)
, also considering resolved factory method definitions.- Specified by:
getResolvableType
in interfaceBeanDefinition
- Overrides:
getResolvableType
in classAbstractBeanDefinition
- Returns:
- the resolvable type (potentially
ResolvableType.NONE
) - Since:
- 5.1
- See Also:
-
getPreferredConstructors
Determine preferred constructors to use for default construction, if any. Constructor arguments will be autowired if necessary.- Returns:
- one or more preferred constructors, or
null
if none (in which case the regular no-arg default constructor will be called) - Since:
- 5.1
-
setUniqueFactoryMethodName
Specify a factory method name that refers to a non-overloaded method. -
setNonUniqueFactoryMethodName
Specify a factory method name that refers to an overloaded method.- Since:
- 5.2
-
isFactoryMethod
Check whether the given candidate qualifies as a factory method. -
setResolvedFactoryMethod
Set a resolved Java Method for the factory method on this bean definition.- Parameters:
method
- the resolved factory method, ornull
to reset it- Since:
- 5.2
-
getResolvedFactoryMethod
Return the resolved factory method as a Java Method object, if available.- Returns:
- the factory method, or
null
if not found or not resolved yet
-
registerExternallyManagedConfigMember
Register an externally managed configuration method or field. -
isExternallyManagedConfigMember
Check whether the given method or field is an externally managed configuration member. -
getExternallyManagedConfigMembers
Return all externally managed configuration methods and fields (as an immutable Set).- Since:
- 5.3.11
-
registerExternallyManagedInitMethod
Register an externally managed configuration initialization method. -
isExternallyManagedInitMethod
Check whether the given method name indicates an externally managed initialization method. -
getExternallyManagedInitMethods
Return all externally managed initialization methods (as an immutable Set).- Since:
- 5.3.11
-
registerExternallyManagedDestroyMethod
Register an externally managed configuration destruction method. -
isExternallyManagedDestroyMethod
Check whether the given method name indicates an externally managed destruction method. -
getExternallyManagedDestroyMethods
Return all externally managed destruction methods (as an immutable Set).- Since:
- 5.3.11
-
cloneBeanDefinition
Description copied from class:AbstractBeanDefinition
Clone this bean definition. To be implemented by concrete subclasses.- Specified by:
cloneBeanDefinition
in classAbstractBeanDefinition
- Returns:
- the cloned bean definition object
-
equals
- Overrides:
equals
in classAbstractBeanDefinition
-
toString
- Overrides:
toString
in classAbstractBeanDefinition
-