Class RootBeanDefinition
- All Implemented Interfaces:
- Serializable,- Cloneable,- BeanMetadataElement,- BeanDefinition,- AttributeAccessor
GenericBeanDefinitions from XML declarations.
 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. This is particularly applicable for
 programmatic definitions derived from factory methods (for example, @Bean methods)
 and instance suppliers (for example, lambda expressions) which come with extra type metadata
 (see setTargetType(ResolvableType)/setResolvedFactoryMethod(Method)).
 
Note: The preferred choice for bean definitions derived from declarative sources
 (for example, XML definitions) is the flexible GenericBeanDefinition variant.
 GenericBeanDefinition comes with the advantage that it allows for dynamically
 defining parent dependencies, not 'hard-coding' the role as a root bean definition,
 even supporting parent relationship changes in the bean post-processor phase.
- Author:
- Rod Johnson, Juergen Hoeller, Sam Brannen
- See Also:
- 
Field SummaryFields inherited from class org.springframework.beans.factory.support.AbstractBeanDefinitionAUTOWIRE_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, ORDER_ATTRIBUTE, PREFERRED_CONSTRUCTORS_ATTRIBUTE, SCOPE_DEFAULTFields inherited from interface org.springframework.beans.factory.config.BeanDefinitionROLE_APPLICATION, ROLE_INFRASTRUCTURE, ROLE_SUPPORT, SCOPE_PROTOTYPE, SCOPE_SINGLETON
- 
Constructor SummaryConstructorsConstructorDescriptionCreate 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.RootBeanDefinition(ResolvableType beanType) Deprecated.
- 
Method SummaryModifier and TypeMethodDescriptionClone this bean definition.booleanReturn the target definition that is being decorated by this bean definition, if any.Get all externally managed configuration methods and fields (as an immutable Set).Get all externally managed destruction methods (as an immutable Set).Get 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 theAnnotatedElementdefining qualifiers, if any.Return aResolvableTypefor 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).booleanisExternallyManagedConfigMember(Member configMember) Determine if the given method or field is an externally managed configuration member.booleanisExternallyManagedDestroyMethod(String destroyMethod) Determine if the given method name indicates an externally managed destruction method.booleanisExternallyManagedInitMethod(String initMethod) Determine if the given method name indicates an externally managed initialization method.booleanisFactoryMethod(Method candidate) Check whether the given candidate qualifies as a factory method.voidMark this bean definition as post-processed, i.e.voidregisterExternallyManagedConfigMember(Member configMember) Register an externally managed configuration method or field.voidregisterExternallyManagedDestroyMethod(String destroyMethod) Register an externally managed configuration destruction method — for example, a method annotated with JSR-250'sPreDestroyannotation.voidregisterExternallyManagedInitMethod(String initMethod) Register an externally managed configuration initialization method — for example, a method annotated with JSR-250'sjavax.annotation.PostConstructor Jakarta'sPostConstructannotation.voidResolve the inferred destroy method if necessary.voidsetDecoratedDefinition(BeanDefinitionHolder decoratedDefinition) Register a target definition that is being decorated by this bean definition.voidSpecify a factory method name that refers to an overloaded method.voidsetParentName(String parentName) Set the name of the parent definition of this bean definition, if any.voidsetQualifiedElement(AnnotatedElement qualifiedElement) Specify theAnnotatedElementdefining qualifiers, to be used instead of the target class or factory method.voidsetResolvedFactoryMethod(Method method) Set a resolved Java Method for the factory method on this bean definition.voidsetTargetType(Class<?> targetType) Specify the target type of this bean definition, if known in advance.voidsetTargetType(ResolvableType targetType) Specify a generics-containing target type of this bean definition, if known in advance.voidSpecify a factory method name that refers to a non-overloaded method.toString()Methods inherited from class org.springframework.beans.factory.support.AbstractBeanDefinitionaddQualifier, applyDefaults, clone, copyQualifiersFrom, getAutowireMode, getBeanClass, getBeanClassName, getConstructorArgumentValues, getDependencyCheck, getDependsOn, getDescription, getDestroyMethodName, getDestroyMethodNames, getFactoryBeanName, getFactoryMethodName, getInitMethodName, getInitMethodNames, getInstanceSupplier, getLazyInit, getMethodOverrides, getOriginatingBeanDefinition, getPropertyValues, getQualifier, getQualifiers, getResolvedAutowireMode, getResource, getResourceDescription, getRole, getScope, hasBeanClass, hasConstructorArgumentValues, hashCode, hasMethodOverrides, hasPropertyValues, hasQualifier, isAbstract, isAutowireCandidate, isBackgroundInit, isDefaultCandidate, isEnforceDestroyMethod, isEnforceInitMethod, isFallback, isLazyInit, isLenientConstructorResolution, isNonPublicAccessAllowed, isPrimary, isPrototype, isSingleton, isSynthetic, overrideFrom, prepareMethodOverride, prepareMethodOverrides, resolveBeanClass, setAbstract, setAutowireCandidate, setAutowireMode, setBackgroundInit, setBeanClass, setBeanClassName, setConstructorArgumentValues, setDefaultCandidate, setDependencyCheck, setDependsOn, setDescription, setDestroyMethodName, setDestroyMethodNames, setEnforceDestroyMethod, setEnforceInitMethod, setFactoryBeanName, setFactoryMethodName, setFallback, setInitMethodName, setInitMethodNames, setInstanceSupplier, setLazyInit, setLenientConstructorResolution, setMethodOverrides, setNonPublicAccessAllowed, setOriginatingBeanDefinition, setPrimary, setPropertyValues, setResource, setResourceDescription, setRole, setScope, setSynthetic, validateMethods inherited from class org.springframework.beans.BeanMetadataAttributeAccessoraddMetadataAttribute, getAttribute, getMetadataAttribute, getSource, removeAttribute, setAttribute, setSourceMethods inherited from class org.springframework.core.AttributeAccessorSupportattributeNames, computeAttribute, copyAttributesFrom, hasAttributeMethods inherited from class java.lang.Objectfinalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.core.AttributeAccessorattributeNames, computeAttribute, getAttribute, hasAttribute, removeAttribute, setAttributeMethods inherited from interface org.springframework.beans.BeanMetadataElementgetSource
- 
Constructor Details- 
RootBeanDefinitionpublic 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)
 
 
- 
RootBeanDefinitionCreate a new RootBeanDefinition for a singleton.- Parameters:
- beanClass- the class of the bean to instantiate
- See Also:
 
- 
RootBeanDefinitionDeprecated.as of 6.0.11, in favor of an extrasetTargetType(ResolvableType)callCreate a new RootBeanDefinition for a singleton.- Parameters:
- beanType- the type of bean to instantiate
- Since:
- 6.0
- See Also:
 
- 
RootBeanDefinitionCreate 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 instantiate
- instanceSupplier- the supplier to construct a bean instance, as an alternative to a declaratively specified factory method
- Since:
- 5.0
- See Also:
 
- 
RootBeanDefinitionpublic 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 instantiate
- scope- the name of the corresponding scope
- instanceSupplier- the supplier to construct a bean instance, as an alternative to a declaratively specified factory method
- Since:
- 5.0
- See Also:
 
- 
RootBeanDefinitionCreate a new RootBeanDefinition for a singleton, using the given autowire mode.- Parameters:
- beanClass- the class of the bean to instantiate
- autowireMode- by name or type, using the constants in this interface
- dependencyCheck- whether to perform a dependency check for objects (not applicable to autowiring a constructor, thus ignored there)
 
- 
RootBeanDefinitionpublic 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 instantiate
- cargs- the constructor argument values to apply
- pvs- the property values to apply
 
- 
RootBeanDefinitionCreate 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
 
- 
RootBeanDefinitionpublic 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 instantiate
- cargs- the constructor argument values to apply
- pvs- the property values to apply
 
- 
RootBeanDefinitionCreate a new RootBeanDefinition as deep copy of the given bean definition.- Parameters:
- original- the original bean definition to copy from
 
 
- 
- 
Method Details- 
getParentNameDescription copied from interface:BeanDefinitionReturn the name of the parent definition of this bean definition, if any.
- 
setParentNameDescription copied from interface:BeanDefinitionSet the name of the parent definition of this bean definition, if any.
- 
setDecoratedDefinitionRegister a target definition that is being decorated by this bean definition.
- 
getDecoratedDefinitionReturn the target definition that is being decorated by this bean definition, if any.
- 
setQualifiedElementSpecify theAnnotatedElementdefining qualifiers, to be used instead of the target class or factory method.- Since:
- 4.3.3
- See Also:
 
- 
getQualifiedElementReturn theAnnotatedElementdefining qualifiers, if any. Otherwise, the factory method and target class will be checked.- Since:
- 4.3.3
 
- 
setTargetTypeSpecify a generics-containing target type of this bean definition, if known in advance.- Since:
- 4.3.3
 
- 
setTargetTypeSpecify the target type of this bean definition, if known in advance.- Since:
- 3.2.2
 
- 
getTargetTypeReturn the target type of this bean definition, if known (either specified in advance or resolved on first instantiation).- Since:
- 3.2.2
 
- 
getResolvableTypeReturn aResolvableTypefor 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:
- getResolvableTypein interface- BeanDefinition
- Overrides:
- getResolvableTypein class- AbstractBeanDefinition
- Returns:
- the resolvable type (potentially ResolvableType.NONE)
- Since:
- 5.1
- See Also:
 
- 
getPreferredConstructorsDetermine preferred constructors to use for default construction, if any. Constructor arguments will be autowired if necessary.As of 6.1, the default implementation of this method takes the AbstractBeanDefinition.PREFERRED_CONSTRUCTORS_ATTRIBUTEattribute into account. Subclasses are encouraged to preserve this through asupercall, either before or after their own preferred constructor determination.- Returns:
- one or more preferred constructors, or nullif none (in which case the regular no-arg default constructor will be called)
- Since:
- 5.1
 
- 
setUniqueFactoryMethodNameSpecify a factory method name that refers to a non-overloaded method.
- 
setNonUniqueFactoryMethodNameSpecify a factory method name that refers to an overloaded method.- Since:
- 5.2
 
- 
isFactoryMethodCheck whether the given candidate qualifies as a factory method.
- 
setResolvedFactoryMethodSet a resolved Java Method for the factory method on this bean definition.- Parameters:
- method- the resolved factory method, or- nullto reset it
- Since:
- 5.2
 
- 
getResolvedFactoryMethodReturn the resolved factory method as a Java Method object, if available.- Returns:
- the factory method, or nullif not found or not resolved yet
 
- 
markAsPostProcessedpublic void markAsPostProcessed()Mark this bean definition as post-processed, i.e. processed byMergedBeanDefinitionPostProcessor.- Since:
- 6.0
 
- 
registerExternallyManagedConfigMemberRegister an externally managed configuration method or field.
- 
isExternallyManagedConfigMemberDetermine if the given method or field is an externally managed configuration member.
- 
getExternallyManagedConfigMembersGet all externally managed configuration methods and fields (as an immutable Set).- Since:
- 5.3.11
 
- 
registerExternallyManagedInitMethodRegister an externally managed configuration initialization method — for example, a method annotated with JSR-250'sjavax.annotation.PostConstructor Jakarta'sPostConstructannotation.The supplied initMethodmay be a simple method name or a qualified method name for package-private andprivatemethods. A qualified name is necessary for package-private andprivatemethods in order to disambiguate between multiple such methods with the same name within a type hierarchy.
- 
isExternallyManagedInitMethodDetermine if the given method name indicates an externally managed initialization method.See registerExternallyManagedInitMethod(java.lang.String)for details regarding the format for the suppliedinitMethod.
- 
getExternallyManagedInitMethodsGet all externally managed initialization methods (as an immutable Set).See registerExternallyManagedInitMethod(java.lang.String)for details regarding the format for the initialization methods in the returned set.- Since:
- 5.3.11
 
- 
resolveDestroyMethodIfNecessarypublic void resolveDestroyMethodIfNecessary()Resolve the inferred destroy method if necessary.- Since:
- 6.0
 
- 
registerExternallyManagedDestroyMethodRegister an externally managed configuration destruction method — for example, a method annotated with JSR-250'sPreDestroyannotation.The supplied destroyMethodmay be the simple method name for non-private methods or the qualified method name forprivatemethods. A qualified name is necessary forprivatemethods in order to disambiguate between multiple private methods with the same name within a class hierarchy.
- 
isExternallyManagedDestroyMethodDetermine if the given method name indicates an externally managed destruction method.See registerExternallyManagedDestroyMethod(java.lang.String)for details regarding the format for the supplieddestroyMethod.
- 
getExternallyManagedDestroyMethodsGet all externally managed destruction methods (as an immutable Set).See registerExternallyManagedDestroyMethod(java.lang.String)for details regarding the format for the destruction methods in the returned set.- Since:
- 5.3.11
 
- 
cloneBeanDefinitionDescription copied from class:AbstractBeanDefinitionClone this bean definition. To be implemented by concrete subclasses.- Specified by:
- cloneBeanDefinitionin class- AbstractBeanDefinition
- Returns:
- the cloned bean definition object
 
- 
equals- Overrides:
- equalsin class- AbstractBeanDefinition
 
- 
toString- Overrides:
- toStringin class- AbstractBeanDefinition
 
 
- 
setTargetType(ResolvableType)call