java.lang.Object | |||||
↳ | org.springframework.core.SimpleAliasRegistry | ||||
↳ | org.springframework.beans.factory.support.DefaultSingletonBeanRegistry | ||||
↳ | org.springframework.beans.factory.support.FactoryBeanRegistrySupport | ||||
↳ | org.springframework.beans.factory.support.AbstractBeanFactory | ||||
↳ | org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory |
Known Direct Subclasses |
Known Indirect Subclasses |
Abstract bean factory superclass that implements default bean creation,
with the full capabilities specified by the RootBeanDefinition
class.
Implements the AutowireCapableBeanFactory
interface in addition to AbstractBeanFactory's createBean(Class, int, boolean)
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 by type. In case of a factory which is capable of searching
its bean definitions, matching beans will typically be implemented through such
a search. For other factory styles, simplified matching algorithms can be implemented.
Note that this class does not assume or implement bean definition
registry capabilities. See DefaultListableBeanFactory
for an implementation
of the ListableBeanFactory
and
BeanDefinitionRegistry
interfaces, which represent the API and SPI
view of such a factory, respectively.
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From interface
org.springframework.beans.factory.BeanFactory
| |||||||||||
From interface
org.springframework.beans.factory.config.AutowireCapableBeanFactory
| |||||||||||
From interface
org.springframework.beans.factory.config.ConfigurableBeanFactory
|
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a new AbstractAutowireCapableBeanFactory.
| |||||||||||
Create a new AbstractAutowireCapableBeanFactory with the given parent.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Apply
BeanPostProcessors to the given existing bean
instance, invoking their postProcessAfterInitialization methods. | |||||||||||
Apply
BeanPostProcessors to the given existing bean
instance, invoking their postProcessBeforeInitialization methods. | |||||||||||
Apply the property values of the bean definition with the given name to
the given bean instance.
| |||||||||||
Instantiate a new bean instance of the given class with the specified autowire
strategy.
| |||||||||||
Populate the given bean instance through applying after-instantiation callbacks
and bean property post-processing (e.g.
| |||||||||||
Autowire the bean properties of the given bean instance by name or type.
| |||||||||||
Configure the given raw bean: autowiring bean properties, applying
bean property values, applying factory callbacks such as
setBeanName
and setBeanFactory , and also applying all bean post processors
(including ones which might wrap the given raw bean). | |||||||||||
Copy all relevant configuration from the given other factory.
| |||||||||||
Fully create a new bean instance of the given class.
| |||||||||||
Fully create a new bean instance of the given class with the specified
autowire strategy.
| |||||||||||
Ignore the given dependency interface for autowiring.
| |||||||||||
Ignore the given dependency type for autowiring:
for example, String.
| |||||||||||
Initialize the given raw bean, applying factory callbacks
such as
setBeanName and setBeanFactory ,
also applying all bean post processors (including ones which
might wrap the given raw bean). | |||||||||||
Resolve the specified dependency against the beans defined in this factory.
| |||||||||||
Set whether to allow circular references between beans - and automatically
try to resolve them.
| |||||||||||
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).
| |||||||||||
Set the instantiation strategy to use for creating bean instances.
| |||||||||||
Set the ParameterNameDiscoverer to use for resolving method parameter
names if needed (e.g.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Apply InstantiationAwareBeanPostProcessors to the specified bean definition
(by class and name), invoking their
postProcessBeforeInstantiation methods. | |||||||||||
Apply MergedBeanDefinitionPostProcessors to the specified bean definition,
invoking their
postProcessMergedBeanDefinition methods. | |||||||||||
Apply the given property values, resolving any runtime references
to other beans in this bean factory.
| |||||||||||
Fill in any missing property values with references to
other beans in this factory if autowire is set to "byName".
| |||||||||||
Abstract method defining "autowire by type" (bean properties by type) behavior.
| |||||||||||
"autowire constructor" (with constructor arguments by type) behavior.
| |||||||||||
Perform a dependency check that all properties exposed have been set,
if desired.
| |||||||||||
Central method of this class: creates a bean instance,
populates the bean instance, applies post-processors, etc.
| |||||||||||
Create a new instance for the specified bean, using an appropriate instantiation strategy:
factory method, constructor autowiring, or simple instantiation.
| |||||||||||
Determine candidate constructors to use for the given bean, checking all registered
SmartInstantiationAwareBeanPostProcessors . | |||||||||||
Actually create the specified bean.
| |||||||||||
Extract a filtered set of PropertyDescriptors from the given BeanWrapper,
excluding ignored dependency types or properties defined on ignored
dependency interfaces.
| |||||||||||
Obtain a reference for early access to the specified bean,
typically for the purpose of resolving a circular reference.
| |||||||||||
Return the instantiation strategy to use for creating bean instances.
| |||||||||||
Return the ParameterNameDiscoverer to use for resolving method parameter
names if needed.
| |||||||||||
This implementation checks the FactoryBean's
getObjectType method
on a plain instance of the FactoryBean, without bean properties applied yet. | |||||||||||
Determine the bean type for the given bean definition which is based on
a factory method.
| |||||||||||
Initialize the given bean instance, applying factory callbacks
as well as init methods and bean post processors.
| |||||||||||
Instantiate the given bean using its default constructor.
| |||||||||||
Instantiate the bean using a named factory method.
| |||||||||||
Invoke the specified custom init method on the given bean.
| |||||||||||
Give a bean a chance to react now all its properties are set,
and a chance to know about its owning bean factory (this object).
| |||||||||||
Determine whether the given bean property is excluded from dependency checks.
| |||||||||||
Populate the bean instance in the given BeanWrapper with the property values
from the bean definition.
| |||||||||||
Applies the
postProcessAfterInitialization callback of all
registered BeanPostProcessors, giving them a chance to post-process the
object obtained from FactoryBeans (for example, to auto-proxy them). | |||||||||||
Predict the eventual bean type (of the processed bean instance) for the
specified bean.
| |||||||||||
Overridden to clear FactoryBean instance cache as well.
| |||||||||||
Apply before-instantiation post-processors, resolving whether there is a
before-instantiation shortcut for the specified bean.
| |||||||||||
Return an array of non-simple bean properties that are unsatisfied.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.beans.factory.support.AbstractBeanFactory
| |||||||||||
From class
org.springframework.beans.factory.support.FactoryBeanRegistrySupport
| |||||||||||
From class
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry
| |||||||||||
From class
org.springframework.core.SimpleAliasRegistry
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
org.springframework.beans.factory.BeanFactory
| |||||||||||
From interface
org.springframework.beans.factory.HierarchicalBeanFactory
| |||||||||||
From interface
org.springframework.beans.factory.config.AutowireCapableBeanFactory
| |||||||||||
From interface
org.springframework.beans.factory.config.ConfigurableBeanFactory
| |||||||||||
From interface
org.springframework.beans.factory.config.SingletonBeanRegistry
| |||||||||||
From interface
org.springframework.core.AliasRegistry
|
Create a new AbstractAutowireCapableBeanFactory.
Create a new AbstractAutowireCapableBeanFactory with the given parent.
parentBeanFactory | parent bean factory, or null if none
|
---|
Apply BeanPostProcessors
to the given existing bean
instance, invoking their postProcessAfterInitialization
methods.
The returned bean instance may be a wrapper around the original.
existingBean | the new bean instance |
---|---|
beanName | the name of the bean |
BeansException |
---|
Apply BeanPostProcessors
to the given existing bean
instance, invoking their postProcessBeforeInitialization
methods.
The returned bean instance may be a wrapper around the original.
existingBean | the new bean instance |
---|---|
beanName | the name of the bean |
BeansException |
---|
Apply the property values of the bean definition with the given name to the given bean instance. The bean definition can either define a fully self-contained bean, reusing its property values, or just property values meant to be used for existing bean instances.
This method does not autowire bean properties; it just applies
explicitly defined property values. Use the autowireBeanProperties(Object, int, boolean)
method to autowire an existing bean instance.
Note: This method requires a bean definition for the given name!
Does not apply standard BeanPostProcessors
callbacks or perform any further initialization of the bean. This interface
offers distinct, fine-grained operations for those purposes, for example
initializeBean(Object, String)
. However, InstantiationAwareBeanPostProcessor
callbacks are applied, if applicable to the configuration of the instance.
existingBean | the existing bean instance |
---|---|
beanName | the name of the bean definition in the bean factory (a bean definition of that name has to be available) |
BeansException |
---|
Instantiate a new bean instance of the given class with the specified autowire
strategy. All constants defined in this interface are supported here.
Can also be invoked with AUTOWIRE_NO
in order to just apply
before-instantiation callbacks (e.g. for annotation-driven injection).
Does not apply standard BeanPostProcessors
callbacks or perform any further initialization of the bean. This interface
offers distinct, fine-grained operations for those purposes, for example
initializeBean(Object, String)
. However, InstantiationAwareBeanPostProcessor
callbacks are applied, if applicable to the construction of the instance.
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 object references in the bean instance (not applicable to autowiring a constructor, thus ignored there) |
BeansException |
---|
Populate the given bean instance through applying after-instantiation callbacks and bean property post-processing (e.g. for annotation-driven injection).
Note: This is essentially intended for (re-)populating annotated fields and
methods, either for new instances or for deserialized instances. It does
not imply traditional by-name or by-type autowiring of properties;
use autowireBeanProperties(Object, int, boolean)
for that purposes.
existingBean | the existing bean instance |
---|
Autowire the bean properties of the given bean instance by name or type.
Can also be invoked with AUTOWIRE_NO
in order to just apply
after-instantiation callbacks (e.g. for annotation-driven injection).
Does not apply standard BeanPostProcessors
callbacks or perform any further initialization of the bean. This interface
offers distinct, fine-grained operations for those purposes, for example
initializeBean(Object, String)
. However, InstantiationAwareBeanPostProcessor
callbacks are applied, if applicable to the configuration of the instance.
existingBean | the existing bean instance |
---|---|
autowireMode | by name or type, using the constants in this interface |
dependencyCheck | whether to perform a dependency check for object references in the bean instance |
BeansException |
---|
Configure the given raw bean: autowiring bean properties, applying
bean property values, applying factory callbacks such as setBeanName
and setBeanFactory
, and also applying all bean post processors
(including ones which might wrap the given raw bean).
This is effectively a superset of what initializeBean(Object, String)
provides,
fully applying the configuration specified by the corresponding bean definition.
Note: This method requires a bean definition for the given name!
existingBean | the existing bean instance |
---|---|
beanName | the name of the bean, to be passed to it if necessary (a bean definition of that name has to be available) |
BeansException |
---|
Copy all relevant configuration from the given other factory.
Should include all standard configuration settings as well as BeanPostProcessors, Scopes, and factory-specific internal settings. Should not include any metadata of actual bean definitions, such as BeanDefinition objects and bean name aliases.
otherFactory | the other BeanFactory to copy from |
---|
Fully create a new bean instance of the given class.
Performs full initialization of the bean, including all applicable
BeanPostProcessors
.
Note: This is intended for creating a fresh instance, populating annotated
fields and methods as well as applying all standard bean initialiation callbacks.
It does not> imply traditional by-name or by-type autowiring of properties;
use createBean(Class, int, boolean)
for that purposes.
beanClass | the class of the bean to create |
---|
BeansException |
---|
Fully create a new bean instance of the given class with the specified autowire strategy. All constants defined in this interface are supported here.
Performs full initialization of the bean, including all applicable
BeanPostProcessors
. This is effectively a superset
of what autowire(Class, int, boolean)
provides, adding initializeBean(Object, String)
behavior.
beanClass | the class of the bean to create |
---|---|
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) |
BeansException |
---|
Ignore the given dependency interface for autowiring.
This will typically be used by application contexts to register dependencies that are resolved in other ways, like BeanFactory through BeanFactoryAware or ApplicationContext through ApplicationContextAware.
By default, only the BeanFactoryAware interface is ignored. For further types to ignore, invoke this method for each type.
Ignore the given dependency type for autowiring: for example, String. Default is none.
Initialize the given raw bean, applying factory callbacks
such as setBeanName
and setBeanFactory
,
also applying all bean post processors (including ones which
might wrap the given raw bean).
Note that no bean definition of the given name has to exist in the bean factory. The passed-in bean name will simply be used for callbacks but not checked against the registered bean definitions.
existingBean | the existing bean instance |
---|---|
beanName | the name of the bean, to be passed to it if necessary
(only passed to BeanPostProcessors ) |
Resolve the specified dependency against the beans defined in this factory.
descriptor | the descriptor for the dependency |
---|---|
beanName | the name of the bean which declares the present dependency |
null
if none foundBeansException |
---|
Set whether to allow circular references between beans - and automatically try to resolve them.
Note that circular reference resolution means that one of the involved beans will receive a reference to another bean that is not fully initialized yet. This can lead to subtle and not-so-subtle side effects on initialization; it does work fine for many scenarios, though.
Default is "true". Turn this off to throw an exception when encountering a circular reference, disallowing them completely.
NOTE: It is generally recommended to not rely on circular references between your beans. Refactor your application logic to have the two beans involved delegate to a third bean that encapsulates their common logic.
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).
This will only be used as a last resort in case of a circular reference that cannot be resolved otherwise: essentially, preferring a raw instance getting injected over a failure of the entire bean wiring process.
Default is "false", as of Spring 2.0. Turn this on to allow for non-wrapped raw beans injected into some of your references, which was Spring 1.2's (arguably unclean) default behavior.
NOTE: It is generally recommended to not rely on circular references between your beans, in particular with auto-proxying involved.
Set the instantiation strategy to use for creating bean instances. Default is CglibSubclassingInstantiationStrategy.
Set the ParameterNameDiscoverer to use for resolving method parameter names if needed (e.g. for constructor names).
Default is none. A typical candidate is
LocalVariableTableParameterNameDiscoverer
,
which implies an ASM dependency and hence isn't set as the default.
Apply InstantiationAwareBeanPostProcessors to the specified bean definition
(by class and name), invoking their postProcessBeforeInstantiation
methods.
Any returned object will be used as the bean instead of actually instantiating
the target bean. A null
return value from the post-processor will
result in the target bean being instantiated.
beanClass | the class of the bean to be instantiated |
---|---|
beanName | the name of the bean |
null
BeansException | if any post-processing failed |
---|
Apply MergedBeanDefinitionPostProcessors to the specified bean definition,
invoking their postProcessMergedBeanDefinition
methods.
mbd | the merged bean definition for the bean |
---|---|
beanType | the actual type of the managed bean instance |
beanName | the name of the bean |
BeansException | if any post-processing failed |
---|
Apply the given property values, resolving any runtime references to other beans in this bean factory. Must use deep copy, so we don't permanently modify this property.
beanName | the bean name passed for better exception information |
---|---|
mbd | the merged bean definition |
bw | the BeanWrapper wrapping the target object |
pvs | the new property values |
Fill in any missing property values with references to other beans in this factory if autowire is set to "byName".
beanName | the name of the bean we're wiring up. Useful for debugging messages; not used functionally. |
---|---|
mbd | bean definition to update through autowiring |
bw | BeanWrapper from which we can obtain information about the bean |
pvs | the PropertyValues to register wired objects with |
Abstract method defining "autowire by type" (bean properties by type) behavior.
This is like PicoContainer default, in which there must be exactly one bean of the property type in the bean factory. This makes bean factories simple to configure for small namespaces, but doesn't work as well as standard Spring behavior for bigger applications.
beanName | the name of the bean to autowire by type |
---|---|
mbd | the merged bean definition to update through autowiring |
bw | BeanWrapper from which we can obtain information about the bean |
pvs | the PropertyValues to register wired objects with |
"autowire constructor" (with constructor arguments by type) behavior. Also applied if explicit constructor argument values are specified, matching all remaining arguments with beans from the bean factory.
This corresponds to constructor injection: In this mode, a Spring bean factory is able to host components that expect constructor-based dependency resolution.
beanName | the name of the bean |
---|---|
mbd | the bean definition for the bean |
ctors | the chosen candidate constructors |
explicitArgs | argument values passed in programmatically via the getBean method,
or null if none (-> use constructor argument values from bean definition) |
Perform a dependency check that all properties exposed have been set, if desired. Dependency checks can be objects (collaborating beans), simple (primitives and String), or all (both).
beanName | the name of the bean |
---|---|
mbd | the merged bean definition the bean was created with |
pds | the relevant property descriptors for the target bean |
pvs | the property values to be applied to the bean |
Central method of this class: creates a bean instance, populates the bean instance, applies post-processors, etc.
beanName | the name of the bean |
---|---|
mbd | the merged bean definition for the bean |
args | arguments to use if creating a prototype using explicit arguments to a
static factory method. This parameter must be null except in this case. |
BeanCreationException |
---|
Create a new instance for the specified bean, using an appropriate instantiation strategy: factory method, constructor autowiring, or simple instantiation.
beanName | the name of the bean |
---|---|
mbd | the bean definition for the bean |
args | arguments to use if creating a prototype using explicit arguments to a static factory method. It is invalid to use a non-null args value in any other case. |
Determine candidate constructors to use for the given bean, checking all registered
SmartInstantiationAwareBeanPostProcessors
.
beanClass | the raw class of the bean |
---|---|
beanName | the name of the bean |
null
if none specifiedBeansException | in case of errors |
---|
Actually create the specified bean. Pre-creation processing has already happened
at this point, e.g. checking postProcessBeforeInstantiation
callbacks.
Differentiates between default bean instantiation, use of a factory method, and autowiring a constructor.
beanName | the name of the bean |
---|---|
mbd | the merged bean definition for the bean |
args | arguments to use if creating a prototype using explicit arguments to a
static factory method. This parameter must be null except in this case. |
BeanCreationException | if the bean could not be created |
---|
Extract a filtered set of PropertyDescriptors from the given BeanWrapper, excluding ignored dependency types or properties defined on ignored dependency interfaces.
bw | the BeanWrapper the bean was created with |
---|
Obtain a reference for early access to the specified bean, typically for the purpose of resolving a circular reference.
beanName | the name of the bean (for error handling purposes) |
---|---|
mbd | the merged bean definition for the bean |
bean | the raw bean instance |
Return the instantiation strategy to use for creating bean instances.
Return the ParameterNameDiscoverer to use for resolving method parameter names if needed.
This implementation checks the FactoryBean's getObjectType
method
on a plain instance of the FactoryBean, without bean properties applied yet.
If this doesn't return a type yet, a full creation of the FactoryBean is
used as fallback (through delegation to the superclass's implementation).
The shortcut check for a FactoryBean is only applied in case of a singleton FactoryBean. If the FactoryBean instance itself is not kept as singleton, it will be fully created to check the type of its exposed object.
beanName | the name of the bean |
---|---|
mbd | the merged bean definition for the bean |
null
elseDetermine the bean type for the given bean definition which is based on a factory method. Only called if there is no singleton instance registered for the target bean already.
This implementation determines the type matching createBean(Class, int, boolean)
's
different creation strategies. As far as possible, we'll perform static
type checking to avoid creation of the target bean.
beanName | the name of the bean (for error handling purposes) |
---|---|
mbd | the merged bean definition for the bean |
typesToMatch | the types to match in case of internal type matching purposes
(also signals that the returned Class will never be exposed to application code) |
null
elseInitialize the given bean instance, applying factory callbacks as well as init methods and bean post processors.
Called from createBean(Class, int, boolean)
for traditionally defined beans,
and from initializeBean(Object, String)
for existing bean instances.
beanName | the bean name in the factory (for debugging purposes) |
---|---|
bean | the new bean instance we may need to initialize |
mbd | the bean definition that the bean was created with
(can also be null , if given an existing bean instance) |
Instantiate the given bean using its default constructor.
beanName | the name of the bean |
---|---|
mbd | the bean definition for the bean |
Instantiate the bean using a named factory method. The method may be static, if the mbd parameter specifies a class, rather than a factoryBean, or an instance variable on a factory object itself configured using Dependency Injection.
beanName | the name of the bean |
---|---|
mbd | the bean definition for the bean |
explicitArgs | argument values passed in programmatically via the getBean method,
or null if none (-> use constructor argument values from bean definition) |
Invoke the specified custom init method on the given bean. Called by invokeInitMethods.
Can be overridden in subclasses for custom resolution of init methods with arguments.
Throwable |
---|
Give a bean a chance to react now all its properties are set, and a chance to know about its owning bean factory (this object). This means checking whether the bean implements InitializingBean or defines a custom init method, and invoking the necessary callback(s) if it does.
beanName | the bean name in the factory (for debugging purposes) |
---|---|
bean | the new bean instance we may need to initialize |
mbd | the merged bean definition that the bean was created with
(can also be null , if given an existing bean instance) |
Throwable | if thrown by init methods or by the invocation process |
---|
Determine whether the given bean property is excluded from dependency checks.
This implementation excludes properties defined by CGLIB and properties whose type matches an ignored dependency type or which are defined by an ignored dependency interface.
pd | the PropertyDescriptor of the bean property |
---|
Populate the bean instance in the given BeanWrapper with the property values from the bean definition.
beanName | the name of the bean |
---|---|
mbd | the bean definition for the bean |
bw | BeanWrapper with bean instance |
Applies the postProcessAfterInitialization
callback of all
registered BeanPostProcessors, giving them a chance to post-process the
object obtained from FactoryBeans (for example, to auto-proxy them).
object | the object obtained from the FactoryBean. |
---|---|
beanName | the name of the bean |
Predict the eventual bean type (of the processed bean instance) for the
specified bean. Called by getType(String)
and isTypeMatch(String, Class)
.
Does not need to handle FactoryBeans specifically, since it is only
supposed to operate on the raw bean type.
This implementation is simplistic in that it is not able to handle factory methods and InstantiationAwareBeanPostProcessors. It only predicts the bean type correctly for a standard bean. To be overridden in subclasses, applying more sophisticated type detection.
beanName | the name of the bean |
---|---|
mbd | the merged bean definition to determine the type for |
typesToMatch | the types to match in case of internal type matching purposes
(also signals that the returned Class will never be exposed to application code) |
null
if not predictable
Overridden to clear FactoryBean instance cache as well.
beanName | the name of the bean |
---|
Apply before-instantiation post-processors, resolving whether there is a before-instantiation shortcut for the specified bean.
beanName | the name of the bean |
---|---|
mbd | the bean definition for the bean |
null
if none
Return an array of non-simple bean properties that are unsatisfied. These are probably unsatisfied references to other beans in the factory. Does not include simple properties like primitives or Strings.
mbd | the merged bean definition the bean was created with |
---|---|
bw | the BeanWrapper the bean was created with |