org.springframework.beans.factory.support

Class RootBeanDefinition

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, BeanMetadataElement, BeanDefinition, AttributeAccessor


    public class RootBeanDefinition
    extends AbstractBeanDefinition
    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:
    GenericBeanDefinition, ChildBeanDefinition, Serialized Form
    • Constructor Detail

      • RootBeanDefinition

        public RootBeanDefinition(@Nullable
                                  java.lang.Class<T> beanClass,
                                  @Nullable
                                  java.util.function.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).
        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:
        AbstractBeanDefinition.setInstanceSupplier(java.util.function.Supplier<?>)
      • RootBeanDefinition

        public RootBeanDefinition(@Nullable
                                  java.lang.Class<T> beanClass,
                                  java.lang.String scope,
                                  @Nullable
                                  java.util.function.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:
        AbstractBeanDefinition.setInstanceSupplier(java.util.function.Supplier<?>)
      • RootBeanDefinition

        public RootBeanDefinition(@Nullable
                                  java.lang.Class<?> beanClass,
                                  int autowireMode,
                                  boolean dependencyCheck)
        Create 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)
      • RootBeanDefinition

        public RootBeanDefinition(@Nullable
                                  java.lang.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
      • RootBeanDefinition

        public RootBeanDefinition(java.lang.String beanClassName)
        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(java.lang.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
      • RootBeanDefinition

        public RootBeanDefinition(RootBeanDefinition original)
        Create a new RootBeanDefinition as deep copy of the given bean definition.
        Parameters:
        original - the original bean definition to copy from
    • Method Detail

      • getParentName

        public java.lang.String getParentName()
        Description copied from interface: BeanDefinition
        Return the name of the parent definition of this bean definition, if any.
      • setParentName

        public void setParentName(@Nullable
                                  java.lang.String parentName)
        Description copied from interface: BeanDefinition
        Set the name of the parent definition of this bean definition, if any.
      • setDecoratedDefinition

        public void setDecoratedDefinition(@Nullable
                                           BeanDefinitionHolder decoratedDefinition)
        Register a target definition that is being decorated by this bean definition.
      • getDecoratedDefinition

        @Nullable
        public BeanDefinitionHolder getDecoratedDefinition()
        Return the target definition that is being decorated by this bean definition, if any.
      • getQualifiedElement

        @Nullable
        public java.lang.reflect.AnnotatedElement getQualifiedElement()
        Return the AnnotatedElement defining qualifiers, if any. Otherwise, the factory method and target class will be checked.
        Since:
        4.3.3
      • setTargetType

        public void setTargetType(ResolvableType targetType)
        Specify a generics-containing target type of this bean definition, if known in advance.
        Since:
        4.3.3
      • setTargetType

        public void setTargetType(@Nullable
                                  java.lang.Class<?> targetType)
        Specify the target type of this bean definition, if known in advance.
        Since:
        3.2.2
      • getTargetType

        @Nullable
        public java.lang.Class<?> getTargetType()
        Return the target type of this bean definition, if known (either specified in advance or resolved on first instantiation).
        Since:
        3.2.2
      • getPreferredConstructors

        @Nullable
        public java.lang.reflect.Constructor<?>[] 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

        public void setUniqueFactoryMethodName(java.lang.String name)
        Specify a factory method name that refers to a non-overloaded method.
      • isFactoryMethod

        public boolean isFactoryMethod(java.lang.reflect.Method candidate)
        Check whether the given candidate qualifies as a factory method.
      • getResolvedFactoryMethod

        @Nullable
        public java.lang.reflect.Method 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

        public void registerExternallyManagedConfigMember(java.lang.reflect.Member configMember)
      • isExternallyManagedConfigMember

        public boolean isExternallyManagedConfigMember(java.lang.reflect.Member configMember)
      • registerExternallyManagedInitMethod

        public void registerExternallyManagedInitMethod(java.lang.String initMethod)
      • isExternallyManagedInitMethod

        public boolean isExternallyManagedInitMethod(java.lang.String initMethod)
      • registerExternallyManagedDestroyMethod

        public void registerExternallyManagedDestroyMethod(java.lang.String destroyMethod)
      • isExternallyManagedDestroyMethod

        public boolean isExternallyManagedDestroyMethod(java.lang.String destroyMethod)