org.springframework.beans.factory.support

Class AbstractBeanDefinition

    • Field Detail

      • SCOPE_DEFAULT

        public static final java.lang.String SCOPE_DEFAULT
        Constant for the default scope name: "", equivalent to singleton status unless overridden from a parent bean definition (if applicable).
        See Also:
        Constant Field Values
      • AUTOWIRE_AUTODETECT

        @Deprecated
        public static final int AUTOWIRE_AUTODETECT
        Deprecated. as of Spring 3.0: If you are using mixed autowiring strategies, use annotation-based autowiring for clearer demarcation of autowiring needs.
        Constant that indicates determining an appropriate autowire strategy through introspection of the bean class.
        See Also:
        setAutowireMode(int), Constant Field Values
      • DEPENDENCY_CHECK_ALL

        public static final int DEPENDENCY_CHECK_ALL
        Constant that indicates dependency checking for all properties (object references as well as "simple" properties).
        See Also:
        setDependencyCheck(int), Constant Field Values
      • INFER_METHOD

        public static final java.lang.String INFER_METHOD
        Constant that indicates the container should attempt to infer the destroy method name for a bean as opposed to explicit specification of a method name. The value "(inferred)" is specifically designed to include characters otherwise illegal in a method name, ensuring no possibility of collisions with legitimately named methods having the same name.

        Currently, the method names detected during destroy method inference are "close" and "shutdown", if present on the specific bean class.

        See Also:
        Constant Field Values
    • Constructor Detail

      • AbstractBeanDefinition

        protected AbstractBeanDefinition()
        Create a new AbstractBeanDefinition with default settings.
      • AbstractBeanDefinition

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

      • overrideFrom

        public void overrideFrom(BeanDefinition other)
        Override settings in this bean definition (presumably a copied parent from a parent-child inheritance relationship) from the given bean definition (presumably the child).
        • Will override beanClass if specified in the given bean definition.
        • Will always take abstract, scope, lazyInit, autowireMode, dependencyCheck, and dependsOn from the given bean definition.
        • Will add constructorArgumentValues, propertyValues, methodOverrides from the given bean definition to existing ones.
        • Will override factoryBeanName, factoryMethodName, initMethodName, and destroyMethodName if specified in the given bean definition.
      • applyDefaults

        public void applyDefaults(BeanDefinitionDefaults defaults)
        Apply the provided default values to this bean.
        Parameters:
        defaults - the defaults to apply
      • setBeanClass

        public void setBeanClass(@Nullable
                                 java.lang.Class<?> beanClass)
        Specify the class for this bean.
      • getBeanClass

        public java.lang.Class<?> getBeanClass()
                                        throws java.lang.IllegalStateException
        Return the class of the wrapped bean, if already resolved.
        Returns:
        the bean class, or null if none defined
        Throws:
        java.lang.IllegalStateException - if the bean definition does not define a bean class, or a specified bean class name has not been resolved into an actual Class
      • hasBeanClass

        public boolean hasBeanClass()
        Return whether this definition specifies a bean class.
      • resolveBeanClass

        @Nullable
        public java.lang.Class<?> resolveBeanClass(@Nullable
                                                             java.lang.ClassLoader classLoader)
                                                      throws java.lang.ClassNotFoundException
        Determine the class of the wrapped bean, resolving it from a specified class name if necessary. Will also reload a specified Class from its name when called with the bean class already resolved.
        Parameters:
        classLoader - the ClassLoader to use for resolving a (potential) class name
        Returns:
        the resolved bean class
        Throws:
        java.lang.ClassNotFoundException - if the class name could be resolved
      • setScope

        public void setScope(@Nullable
                             java.lang.String scope)
        Set the name of the target scope for the bean.

        The default is singleton status, although this is only applied once a bean definition becomes active in the containing factory. A bean definition may eventually inherit its scope from a parent bean definition. For this reason, the default scope name is an empty string (i.e., ""), with singleton status being assumed until a resolved scope is set.

        Specified by:
        setScope in interface BeanDefinition
        See Also:
        BeanDefinition.SCOPE_SINGLETON, BeanDefinition.SCOPE_PROTOTYPE
      • getScope

        @Nullable
        public java.lang.String getScope()
        Return the name of the target scope for the bean.
        Specified by:
        getScope in interface BeanDefinition
      • setAbstract

        public void setAbstract(boolean abstractFlag)
        Set if this bean is "abstract", i.e. not meant to be instantiated itself but rather just serving as parent for concrete child bean definitions.

        Default is "false". Specify true to tell the bean factory to not try to instantiate that particular bean in any case.

      • isAbstract

        public boolean isAbstract()
        Return whether this bean is "abstract", i.e. not meant to be instantiated itself but rather just serving as parent for concrete child bean definitions.
        Specified by:
        isAbstract in interface BeanDefinition
      • setLazyInit

        public void setLazyInit(boolean lazyInit)
        Set whether this bean should be lazily initialized.

        If false, the bean will get instantiated on startup by bean factories that perform eager initialization of singletons.

        Specified by:
        setLazyInit in interface BeanDefinition
      • isLazyInit

        public boolean isLazyInit()
        Return whether this bean should be lazily initialized, i.e. not eagerly instantiated on startup. Only applicable to a singleton bean.
        Specified by:
        isLazyInit in interface BeanDefinition
      • setAutowireMode

        public void setAutowireMode(int autowireMode)
        Set the autowire mode. This determines whether any automagical detection and setting of bean references will happen. Default is AUTOWIRE_NO, which means there's no autowire.
        Parameters:
        autowireMode - the autowire mode to set. Must be one of the constants defined in this class.
        See Also:
        AUTOWIRE_NO, AUTOWIRE_BY_NAME, AUTOWIRE_BY_TYPE, AUTOWIRE_CONSTRUCTOR, AUTOWIRE_AUTODETECT
      • getAutowireMode

        public int getAutowireMode()
        Return the autowire mode as specified in the bean definition.
      • getDependencyCheck

        public int getDependencyCheck()
        Return the dependency check code.
      • setDependsOn

        public void setDependsOn(@Nullable
                                 java.lang.String... dependsOn)
        Set the names of the beans that this bean depends on being initialized. The bean factory will guarantee that these beans get initialized first.

        Note that dependencies are normally expressed through bean properties or constructor arguments. This property should just be necessary for other kinds of dependencies like statics (*ugh*) or database preparation on startup.

        Specified by:
        setDependsOn in interface BeanDefinition
      • setAutowireCandidate

        public void setAutowireCandidate(boolean autowireCandidate)
        Set whether this bean is a candidate for getting autowired into some other bean.

        Note that this flag is designed to only affect type-based autowiring. It does not affect explicit references by name, which will get resolved even if the specified bean is not marked as an autowire candidate. As a consequence, autowiring by name will nevertheless inject a bean if the name matches.

        Specified by:
        setAutowireCandidate in interface BeanDefinition
        See Also:
        AUTOWIRE_BY_TYPE, AUTOWIRE_BY_NAME
      • isAutowireCandidate

        public boolean isAutowireCandidate()
        Return whether this bean is a candidate for getting autowired into some other bean.
        Specified by:
        isAutowireCandidate in interface BeanDefinition
      • setPrimary

        public void setPrimary(boolean primary)
        Set whether this bean is a primary autowire candidate.

        If this value is true for exactly one bean among multiple matching candidates, it will serve as a tie-breaker.

        Specified by:
        setPrimary in interface BeanDefinition
      • isPrimary

        public boolean isPrimary()
        Return whether this bean is a primary autowire candidate.
        Specified by:
        isPrimary in interface BeanDefinition
      • hasQualifier

        public boolean hasQualifier(java.lang.String typeName)
        Return whether this bean has the specified qualifier.
      • copyQualifiersFrom

        public void copyQualifiersFrom(AbstractBeanDefinition source)
        Copy the qualifiers from the supplied AbstractBeanDefinition to this bean definition.
        Parameters:
        source - the AbstractBeanDefinition to copy from
      • setInstanceSupplier

        public void setInstanceSupplier(@Nullable
                                        java.util.function.Supplier<?> instanceSupplier)
        Specify a callback for creating an instance of the bean, as an alternative to a declaratively specified factory method.

        If such a callback is set, it will override any other constructor or factory method metadata. However, bean property population and potential annotation-driven injection will still apply as usual.

        Since:
        5.0
        See Also:
        setConstructorArgumentValues(ConstructorArgumentValues), setPropertyValues(MutablePropertyValues)
      • getInstanceSupplier

        @Nullable
        public java.util.function.Supplier<?> getInstanceSupplier()
        Return a callback for creating an instance of the bean, if any.
        Since:
        5.0
      • setNonPublicAccessAllowed

        public void setNonPublicAccessAllowed(boolean nonPublicAccessAllowed)
        Specify whether to allow access to non-public constructors and methods, for the case of externalized metadata pointing to those. The default is true; switch this to false for public access only.

        This applies to constructor resolution, factory method resolution, and also init/destroy methods. Bean property accessors have to be public in any case and are not affected by this setting.

        Note that annotation-driven configuration will still access non-public members as far as they have been annotated. This setting applies to externalized metadata in this bean definition only.

      • isNonPublicAccessAllowed

        public boolean isNonPublicAccessAllowed()
        Return whether to allow access to non-public constructors and methods.
      • setLenientConstructorResolution

        public void setLenientConstructorResolution(boolean lenientConstructorResolution)
        Specify whether to resolve constructors in lenient mode (true, which is the default) or to switch to strict resolution (throwing an exception in case of ambiguous constructors that all match when converting the arguments, whereas lenient mode would use the one with the 'closest' type matches).
      • isLenientConstructorResolution

        public boolean isLenientConstructorResolution()
        Return whether to resolve constructors in lenient mode or in strict mode.
      • setConstructorArgumentValues

        public void setConstructorArgumentValues(ConstructorArgumentValues constructorArgumentValues)
        Specify constructor argument values for this bean.
      • hasConstructorArgumentValues

        public boolean hasConstructorArgumentValues()
        Return if there are constructor argument values defined for this bean.
        Specified by:
        hasConstructorArgumentValues in interface BeanDefinition
      • setPropertyValues

        public void setPropertyValues(MutablePropertyValues propertyValues)
        Specify property values for this bean, if any.
      • hasPropertyValues

        public boolean hasPropertyValues()
        Return if there are property values values defined for this bean.
        Specified by:
        hasPropertyValues in interface BeanDefinition
        Since:
        5.0.2
      • setMethodOverrides

        public void setMethodOverrides(MethodOverrides methodOverrides)
        Specify method overrides for the bean, if any.
      • getMethodOverrides

        public MethodOverrides getMethodOverrides()
        Return information about methods to be overridden by the IoC container. This will be empty if there are no method overrides.

        Never returns null.

      • hasMethodOverrides

        public boolean hasMethodOverrides()
        Return if there are method overrides defined for this bean.
        Since:
        5.0.2
      • setInitMethodName

        public void setInitMethodName(@Nullable
                                      java.lang.String initMethodName)
        Set the name of the initializer method.

        The default is null in which case there is no initializer method.

        Specified by:
        setInitMethodName in interface BeanDefinition
      • setEnforceInitMethod

        public void setEnforceInitMethod(boolean enforceInitMethod)
        Specify whether or not the configured init method is the default.

        The default value is false.

        See Also:
        setInitMethodName(java.lang.String)
      • isEnforceInitMethod

        public boolean isEnforceInitMethod()
        Indicate whether the configured init method is the default.
        See Also:
        getInitMethodName()
      • setDestroyMethodName

        public void setDestroyMethodName(@Nullable
                                         java.lang.String destroyMethodName)
        Set the name of the destroy method.

        The default is null in which case there is no destroy method.

        Specified by:
        setDestroyMethodName in interface BeanDefinition
      • setEnforceDestroyMethod

        public void setEnforceDestroyMethod(boolean enforceDestroyMethod)
        Specify whether or not the configured destroy method is the default.

        The default value is false.

        See Also:
        setDestroyMethodName(java.lang.String)
      • isEnforceDestroyMethod

        public boolean isEnforceDestroyMethod()
        Indicate whether the configured destroy method is the default.
        See Also:
        getDestroyMethodName()
      • setSynthetic

        public void setSynthetic(boolean synthetic)
        Set whether this bean definition is 'synthetic', that is, not defined by the application itself (for example, an infrastructure bean such as a helper for auto-proxying, created through <aop:config>).
      • isSynthetic

        public boolean isSynthetic()
        Return whether this bean definition is 'synthetic', that is, not defined by the application itself.
      • setDescription

        public void setDescription(@Nullable
                                   java.lang.String description)
        Set a human-readable description of this bean definition.
        Specified by:
        setDescription in interface BeanDefinition
      • getDescription

        @Nullable
        public java.lang.String getDescription()
        Return a human-readable description of this bean definition.
        Specified by:
        getDescription in interface BeanDefinition
      • setResource

        public void setResource(@Nullable
                                Resource resource)
        Set the resource that this bean definition came from (for the purpose of showing context in case of errors).
      • getResource

        @Nullable
        public Resource getResource()
        Return the resource that this bean definition came from.
      • setResourceDescription

        public void setResourceDescription(@Nullable
                                           java.lang.String resourceDescription)
        Set a description of the resource that this bean definition came from (for the purpose of showing context in case of errors).
      • getResourceDescription

        @Nullable
        public java.lang.String getResourceDescription()
        Return a description of the resource that this bean definition came from (for the purpose of showing context in case of errors).
        Specified by:
        getResourceDescription in interface BeanDefinition
      • setOriginatingBeanDefinition

        public void setOriginatingBeanDefinition(BeanDefinition originatingBd)
        Set the originating (e.g. decorated) BeanDefinition, if any.
      • getOriginatingBeanDefinition

        @Nullable
        public BeanDefinition getOriginatingBeanDefinition()
        Return the originating BeanDefinition, or null if none. Allows for retrieving the decorated bean definition, if any.

        Note that this method returns the immediate originator. Iterate through the originator chain to find the original BeanDefinition as defined by the user.

        Specified by:
        getOriginatingBeanDefinition in interface BeanDefinition
      • prepareMethodOverride

        protected void prepareMethodOverride(MethodOverride mo)
                                      throws BeanDefinitionValidationException
        Validate and prepare the given method override. Checks for existence of a method with the specified name, marking it as not overloaded if none found.
        Parameters:
        mo - the MethodOverride object to validate
        Throws:
        BeanDefinitionValidationException - in case of validation failure
      • clone

        public java.lang.Object clone()
        Public declaration of Object's clone() method. Delegates to cloneBeanDefinition().
        Overrides:
        clone in class java.lang.Object
        See Also:
        Object.clone()
      • cloneBeanDefinition

        public abstract AbstractBeanDefinition cloneBeanDefinition()
        Clone this bean definition. To be implemented by concrete subclasses.
        Returns:
        the cloned bean definition object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object