RootBeanDefinition class.
Implements the org.springframework.beans.factory.config.AutowireCapableBeanFactory
interface in addition to AbstractBeanFactory's createBean method.
Provides bean creation (with constructor resolution), property population, wiring (including autowiring), and initialization. Handles runtime bean references, resolves managed collections, calls initialization methods, etc. Supports autowiring constructors, properties by name, and properties by type.
The main template method to be implemented by subclasses is
resolveDependency(DependencyDescriptor, String, Set, TypeConverter), used for
autowiring. In case of a org.
which is capable of searching its bean definitions, matching beans will typically be
implemented through such a search. Otherwise, simplified matching can be implemented.
Note that this class does not assume or implement bean definition
registry capabilities. See DefaultListableBeanFactory for an implementation
of the org. and
BeanDefinitionRegistry interfaces, which represent the API and SPI
view of such a factory, respectively.
RootBeanDefinition, DefaultListableBeanFactory, BeanDefinitionRegistry
| Modifier and Type | Class and Description |
|---|---|
| private static class | AbstractAutowireCapableBeanFactory.
Special DependencyDescriptor variant for Spring's good old autowire="byType" mode. |
| private static class | AbstractAutowireCapableBeanFactory.
|
| private static class | AbstractAutowireCapableBeanFactory.
|
| Modifier and Type | Field and Description |
|---|---|
| private boolean | allowCircularReferences
Whether to automatically try to resolve circular references between beans. |
| private boolean | allowRawInjectionDespiteWrapping
Whether to resort to injecting a raw bean instance in case of circular reference, even if the injected bean eventually got wrapped. |
| private final NamedThreadLocal | currentlyCreatedBean
The name of the currently created bean, for implicit dependency registration on getBean etc invocations triggered from a user-specified Supplier callback. |
| private final ConcurrentMap | factoryBeanInstanceCache
Cache of unfinished FactoryBean instances: FactoryBean name to BeanWrapper. |
| private final ConcurrentMap | factoryMethodCandidateCache
Cache of candidate factory methods per factory class. |
| private final ConcurrentMap | filteredPropertyDescriptorsCache
Cache of filtered PropertyDescriptors: bean Class to PropertyDescriptor array. |
| private final Set | ignoredDependencyInterfaces
Dependency interfaces to ignore on dependency check and autowire, as Set of Class objects. |
| private final Set | ignoredDependencyTypes
Dependency types to ignore on dependency check and autowire, as Set of Class objects: for example, String. |
| private InstantiationStrategy | instantiationStrategy
Strategy for creating bean instances. |
| private ParameterNameDiscoverer | parameterNameDiscoverer
Resolver strategy for method parameter names. |
| Access | Constructor and Description |
|---|---|
| public | |
| public | AbstractAutowireCapableBeanFactory(BeanFactory
parent bean factory, or parentBeanFactory)null if noneCreate a new AbstractAutowireCapableBeanFactory with the given parent. |
| Modifier and Type | Method and Description |
|---|---|
| public Object | applyBeanPostProcessorsAfterInitialization(Object
the existing bean instance existingBean, String the name of the bean, to be passed to it if necessary
(only passed to beanName)
BeanPostProcessors;
can follow the ORIGINAL_INSTANCE_SUFFIX convention in order to
enforce the given instance to be returned, i.e. no proxies etc)
Deprecated
since 6.1.
Apply |
| public Object | applyBeanPostProcessorsBeforeInitialization(Object
the existing bean instance existingBean, String the name of the bean, to be passed to it if necessary
(only passed to beanName)
BeanPostProcessors;
can follow the ORIGINAL_INSTANCE_SUFFIX convention in order to
enforce the given instance to be returned, i.e. no proxies etc)
Deprecated
since 6.1.
Apply |
| protected Object | Returns: the bean object to use instead of a default instance of the target bean, ornullthe class of the bean to be instantiated beanClass, String the name of the bean beanName)Apply InstantiationAwareBeanPostProcessors to the specified bean definition
(by class and name), invoking their |
| public void | applyBeanPropertyValues(Object
the existing bean instance existingBean, String the name of the bean definition in the bean factory
(a bean definition of that name has to be available) beanName)Implements org. Apply the property values of the bean definition with the given name to the given bean instance. |
| protected void | applyMergedBeanDefinitionPostProcessors(RootBeanDefinition
the merged bean definition for the bean mbd, Class<?> the actual type of the managed bean instance beanType, String the name of the bean beanName)Apply MergedBeanDefinitionPostProcessors to the specified bean definition,
invoking their |
| protected void | applyPropertyValues(String
the bean name passed for better exception information beanName, BeanDefinition the merged bean definition mbd, BeanWrapper the BeanWrapper wrapping the target object bw, PropertyValues the new property values pvs)Apply the given property values, resolving any runtime references to other beans in this bean factory. |
| public Object | autowire(Class<?>
the class of the bean to instantiate beanClass, int by name or type, using the constants in this interface autowireMode, boolean whether to perform a dependency check for object
references in the bean instance (not applicable to autowiring a constructor,
thus ignored there) dependencyCheck)Implements org. Instantiate a new bean instance of the given class with the specified autowire strategy. |
| public void | autowireBean(Object
the existing bean instance existingBean)Implements org. Populate the given bean instance through applying after-instantiation callbacks and bean property post-processing (e.g. for annotation-driven injection). |
| public void | autowireBeanProperties(Object
the existing bean instance existingBean, int by name or type, using the constants in this interface autowireMode, boolean whether to perform a dependency check for object
references in the bean instance dependencyCheck)Implements org. Autowire the bean properties of the given bean instance by name or type. |
| protected void | autowireByName(String
the name of the bean we're wiring up.
Useful for debugging messages; not used functionally. beanName, AbstractBeanDefinition bean definition to update through autowiring mbd, BeanWrapper the BeanWrapper from which we can obtain information about the bean bw, MutablePropertyValues the PropertyValues to register wired objects with pvs)Fill in any missing property values with references to other beans in this factory if autowire is set to "byName". |
| protected void | autowireByType(String
the name of the bean to autowire by type beanName, AbstractBeanDefinition the merged bean definition to update through autowiring mbd, BeanWrapper the BeanWrapper from which we can obtain information about the bean bw, MutablePropertyValues the PropertyValues to register wired objects with pvs)Abstract method defining "autowire by type" (bean properties by type) behavior. |
| protected BeanWrapper | Returns: a BeanWrapper for the new instancethe name of the bean beanName, RootBeanDefinition the bean definition for the bean mbd, Constructor<?>[] the chosen candidate constructors ctors, Object[] argument values passed in programmatically via the getBean method,
or explicitArgs)null if none (implying the use of constructor argument values from bean definition)"autowire constructor" (with constructor arguments by type) behavior. |
| protected void | checkDependencies(String
the name of the bean beanName, AbstractBeanDefinition the merged bean definition the bean was created with mbd, PropertyDescriptor[] the relevant property descriptors for the target bean pds, PropertyValues the property values to be applied to the bean pvs)Perform a dependency check that all properties exposed have been set, if desired. |
| protected void | clearSingletonCache()
Overrides org. Overridden to clear FactoryBean instance cache as well. |
| public Object | configureBean(Object
the existing bean instance existingBean, String the name of the bean, to be passed to it if necessary
(a bean definition of that name has to be available) beanName)Implements org. Configure the given raw bean: autowiring bean properties, applying
bean property values, applying factory callbacks such as |
| private Object | convertForProperty(Object value, String propertyName, BeanWrapper bw, TypeConverter converter)
Convert the given value for the specified target property. |
| public void | copyConfigurationFrom(ConfigurableBeanFactory
the other BeanFactory to copy from otherFactory)Overrides org. Implements org. Copy all relevant configuration from the given other factory. |
| public <T> T | createBean(Class<T>
the class of the bean to create beanClass)Implements org. Fully create a new bean instance of the given class. |
| public Object | createBean(Class<?>
the class of the bean to create beanClass, int by name or type, using the constants in this interface autowireMode, boolean whether to perform a dependency check for objects
(not applicable to autowiring a constructor, thus ignored there) dependencyCheck)Implements org.
Deprecated
Fully create a new bean instance of the given class with the specified autowire strategy. |
| protected Object | createBean(String
the name of the bean beanName, RootBeanDefinition the merged bean definition for the bean mbd, Object[] explicit arguments to use for constructor or factory method invocation args)Implements abstract org. Central method of this class: creates a bean instance, populates the bean instance, applies post-processors, etc. |
| protected BeanWrapper | Returns: a BeanWrapper for the new instancethe name of the bean beanName, RootBeanDefinition the bean definition for the bean mbd, Object[] explicit arguments to use for constructor or factory method invocation args)Create a new instance for the specified bean, using an appropriate instantiation strategy: factory method, constructor autowiring, or simple instantiation. |
| public void | destroyBean(Object
the bean instance to destroy existingBean)Implements org. Destroy the given bean instance (typically coming from |
| protected Constructor | Returns: the candidate constructors, ornull if none specifiedthe raw class of the bean beanClass, String the name of the bean beanName)Determine candidate constructors to use for the given bean, checking all registered
|
| protected Class | Returns: the type for the bean if determinable, ornull otherwisethe name of the bean (for error handling purposes) beanName, RootBeanDefinition the merged bean definition for the bean mbd, Class<?>... the types to match in case of internal type matching purposes
(also signals that the returned typesToMatch)Class will never be exposed to application code)Determine the target type for the given bean definition. |
| protected Object | Returns: a new instance of the beanthe name of the bean beanName, RootBeanDefinition the merged bean definition for the bean mbd, Object[] explicit arguments to use for constructor or factory method invocation args)Actually create the specified bean. |
| protected PropertyDescriptor[] | Returns: the filtered PropertyDescriptorsthe BeanWrapper the bean was created with bw, boolean whether to cache filtered PropertyDescriptors for the given bean Class cache)Extract a filtered set of PropertyDescriptors from the given BeanWrapper, excluding ignored dependency types or properties defined on ignored dependency interfaces. |
| protected PropertyDescriptor[] | Returns: the filtered PropertyDescriptorsthe BeanWrapper the bean was created with bw)Extract a filtered set of PropertyDescriptors from the given BeanWrapper, excluding ignored dependency types or properties defined on ignored dependency interfaces. |
| protected Object | Returns: the object to expose as bean referencethe name of the bean (for error handling purposes) beanName, RootBeanDefinition the merged bean definition for the bean mbd, Object the raw bean instance bean)Obtain a reference for early access to the specified bean, typically for the purpose of resolving a circular reference. |
| public InstantiationStrategy | |
| pack-priv Log | |
| private FactoryBean | Returns: the FactoryBean instance, ornull to indicate
that we couldn't obtain a shortcut FactoryBean instancethe name of the bean beanName, RootBeanDefinition the bean definition for the bean mbd)Obtain a "shortcut" non-singleton FactoryBean instance to use for a
|
| protected Object | getObjectForBeanInstance(Object
the shared bean instance beanInstance, String the name that may include factory dereference prefix name, String the canonical bean name beanName, RootBeanDefinition the merged bean definition mbd)Overrides org. Overridden in order to implicitly register the currently created bean as
dependent on further beans getting programmatically retrieved during a
|
| public ParameterNameDiscoverer | getParameterNameDiscoverer()
Return the ParameterNameDiscoverer to use for resolving method parameter names if needed. |
| private FactoryBean | Returns: the FactoryBean instance, ornull to indicate
that we couldn't obtain a shortcut FactoryBean instancethe name of the bean beanName, RootBeanDefinition the bean definition for the bean mbd)Obtain a "shortcut" singleton FactoryBean instance to use for a
|
| protected ResolvableType | getTypeForFactoryBean(String
the name of the bean beanName, RootBeanDefinition the merged bean definition for the bean mbd, boolean if initialization of the FactoryBean is permitted if the type
cannot be determined another way allowInit)Overrides org. This implementation attempts to query the FactoryBean's generic parameter metadata if present to determine the object type. |
| private ResolvableType | Returns: the commonFactoryBean object type, or null if nonethe bean class to find the factory method on beanClass, String the name of the factory method factoryMethodName)Introspect the factory method signatures on the given bean class,
trying to find a common |
| protected Class | Returns: the type for the bean if determinable, ornull otherwisethe name of the bean (for error handling purposes) beanName, RootBeanDefinition the merged bean definition for the bean mbd, Class<?>... the types to match in case of internal type matching purposes
(also signals that the returned typesToMatch)Class will never be exposed to application code)Determine the target type for the given bean definition which is based on a factory method. |
| public void | |
| public void | ignoreDependencyType(Class<?> type)
Ignore the given dependency type for autowiring: for example, String. |
| public Object | initializeBean(Object
the existing bean instance existingBean, String the name of the bean, to be passed to it if necessary
(only passed to beanName)BeanPostProcessors;
can follow the ORIGINAL_INSTANCE_SUFFIX convention in order to
enforce the given instance to be returned, i.e. no proxies etc)Implements org. Initialize the given raw bean, applying factory callbacks
such as |
| protected Object | Returns: the initialized bean instance (potentially wrapped)the bean name in the factory (for debugging purposes) beanName, Object the new bean instance we may need to initialize bean, RootBeanDefinition the bean definition that the bean was created with
(can also be mbd)null, if given an existing bean instance)Initialize the given bean instance, applying factory callbacks as well as init methods and bean post processors. |
| protected BeanWrapper | Returns: a BeanWrapper for the new instancethe name of the bean beanName, RootBeanDefinition the bean definition for the bean mbd)Instantiate the given bean using its default constructor. |
| protected BeanWrapper | Returns: a BeanWrapper for the new instancethe name of the bean beanName, RootBeanDefinition the bean definition for the bean mbd, Object[] argument values passed in programmatically via the getBean method,
or explicitArgs)null if none (implying the use of constructor argument values from bean definition)Instantiate the bean using a named factory method. |
| private void | |
| protected void | invokeCustomInitMethod(String beanName, Object bean, RootBeanDefinition mbd, String initMethodName)
Invoke the specified custom init method on the given bean. |
| protected void | invokeInitMethods(String
the bean name in the factory (for debugging purposes) beanName, Object the new bean instance we may need to initialize bean, RootBeanDefinition the merged bean definition that the bean was created with
(can also be mbd)null, if given an existing bean instance)Give a bean a chance to initialize itself after all its properties are set, and a chance to know about its owning bean factory (this object). |
| public boolean | |
| public boolean | |
| private boolean | isConvertibleProperty(String propertyName, BeanWrapper bw)
Determine whether the factory should cache a converted value for the given property. |
| protected boolean | Returns: whether the bean property is excludedthe PropertyDescriptor of the bean property pd)Determine whether the given bean property is excluded from dependency checks. |
| private BeanWrapper | Returns: a BeanWrapper for the new instancethe configured supplier supplier, String the corresponding bean name beanName, RootBeanDefinition mbd)Obtain a bean instance from the given supplier. |
| protected Object | Returns: the bean instance (possiblynull)the configured supplier supplier, String the corresponding bean name beanName, RootBeanDefinition the bean definition for the bean mbd)Obtain a bean instance from the given supplier. |
| protected void | populateBean(String
the name of the bean beanName, RootBeanDefinition the bean definition for the bean mbd, BeanWrapper the BeanWrapper with bean instance bw)Populate the bean instance in the given BeanWrapper with the property values from the bean definition. |
| protected Object | postProcessObjectFromFactoryBean(Object
the object obtained from the FactoryBean. object, String the name of the bean beanName)
Applies the |
| protected Class | predictBeanType(String
the name of the bean beanName, RootBeanDefinition the merged bean definition to determine the type for mbd, Class<?>... the types to match in case of internal type matching purposes
(also signals that the returned typesToMatch)Class will never be exposed to application code)Overrides org. Predict the eventual bean type (of the processed bean instance) for the specified bean. |
| protected void | removeSingleton(String
the name of the bean beanName)Overrides org. Overridden to clear FactoryBean instance cache as well. |
| public Object | resolveBeanByName(String
the name of the bean to look up name, DependencyDescriptor the dependency descriptor for the requesting injection point descriptor)Implements org. Resolve a bean instance for the given bean name, providing a dependency descriptor for exposure to target factory methods. |
| protected Object | Returns: the shortcut-determined bean instance, ornull if nonethe name of the bean beanName, RootBeanDefinition the bean definition for the bean mbd)Apply before-instantiation post-processors, resolving whether there is a before-instantiation shortcut for the specified bean. |
| public Object | resolveDependency(DependencyDescriptor
the descriptor for the dependency (field/method/constructor) descriptor, String the name of the bean which declares the given dependency requestingBeanName)Implements org. Resolve the specified dependency against the beans defined in this factory. |
| public void | setAllowCircularReferences(boolean allowCircularReferences)
Set whether to allow circular references between beans - and automatically try to resolve them. |
| public void | setAllowRawInjectionDespiteWrapping(boolean allowRawInjectionDespiteWrapping)
Set whether to allow the raw injection of a bean instance into some other bean's property, despite the injected bean eventually getting wrapped (for example, through AOP auto-proxying). |
| public void | setInstantiationStrategy(InstantiationStrategy instantiationStrategy)
Set the instantiation strategy to use for creating bean instances. |
| public void | setParameterNameDiscoverer(ParameterNameDiscoverer parameterNameDiscoverer)
Set the ParameterNameDiscoverer to use for resolving method parameter names if needed (e.g. for constructor names). |
| protected String[] | Returns: an array of bean property namesthe merged bean definition the bean was created with mbd, BeanWrapper the BeanWrapper the bean was created with bw)Return an array of non-simple bean properties that are unsatisfied. |