public abstract class

AbstractAutowireCapableBeanFactory

extends AbstractBeanFactory
implements AutowireCapableBeanFactory
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

Class Overview

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.

Summary

[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
AbstractAutowireCapableBeanFactory()
Create a new AbstractAutowireCapableBeanFactory.
AbstractAutowireCapableBeanFactory(BeanFactory parentBeanFactory)
Create a new AbstractAutowireCapableBeanFactory with the given parent.
Public Methods
Object applyBeanPostProcessorsAfterInitialization(Object existingBean, String beanName)
Apply BeanPostProcessors to the given existing bean instance, invoking their postProcessAfterInitialization methods.
Object applyBeanPostProcessorsBeforeInitialization(Object existingBean, String beanName)
Apply BeanPostProcessors to the given existing bean instance, invoking their postProcessBeforeInitialization methods.
void applyBeanPropertyValues(Object existingBean, String beanName)
Apply the property values of the bean definition with the given name to the given bean instance.
Object autowire(Class beanClass, int autowireMode, boolean dependencyCheck)
Instantiate a new bean instance of the given class with the specified autowire strategy.
void autowireBean(Object existingBean)
Populate the given bean instance through applying after-instantiation callbacks and bean property post-processing (e.g.
void autowireBeanProperties(Object existingBean, int autowireMode, boolean dependencyCheck)
Autowire the bean properties of the given bean instance by name or type.
Object configureBean(Object existingBean, String beanName)
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).
void copyConfigurationFrom(ConfigurableBeanFactory otherFactory)
Copy all relevant configuration from the given other factory.
<T> T createBean(Class<T> beanClass)
Fully create a new bean instance of the given class.
Object createBean(Class beanClass, int autowireMode, boolean dependencyCheck)
Fully create a new bean instance of the given class with the specified autowire strategy.
void ignoreDependencyInterface(Class ifc)
Ignore the given dependency interface for autowiring.
void ignoreDependencyType(Class type)
Ignore the given dependency type for autowiring: for example, String.
Object initializeBean(Object existingBean, String beanName)
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).
Object resolveDependency(DependencyDescriptor descriptor, String beanName)
Resolve the specified dependency against the beans defined in this factory.
void setAllowCircularReferences(boolean allowCircularReferences)
Set whether to allow circular references between beans - and automatically try to resolve them.
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).
void setInstantiationStrategy(InstantiationStrategy instantiationStrategy)
Set the instantiation strategy to use for creating bean instances.
void setParameterNameDiscoverer(ParameterNameDiscoverer parameterNameDiscoverer)
Set the ParameterNameDiscoverer to use for resolving method parameter names if needed (e.g.
Protected Methods
Object applyBeanPostProcessorsBeforeInstantiation(Class beanClass, String beanName)
Apply InstantiationAwareBeanPostProcessors to the specified bean definition (by class and name), invoking their postProcessBeforeInstantiation methods.
void applyMergedBeanDefinitionPostProcessors(RootBeanDefinition mbd, Class beanType, String beanName)
Apply MergedBeanDefinitionPostProcessors to the specified bean definition, invoking their postProcessMergedBeanDefinition methods.
void applyPropertyValues(String beanName, BeanDefinition mbd, BeanWrapper bw, PropertyValues pvs)
Apply the given property values, resolving any runtime references to other beans in this bean factory.
void autowireByName(String beanName, AbstractBeanDefinition mbd, BeanWrapper bw, MutablePropertyValues pvs)
Fill in any missing property values with references to other beans in this factory if autowire is set to "byName".
void autowireByType(String beanName, AbstractBeanDefinition mbd, BeanWrapper bw, MutablePropertyValues pvs)
Abstract method defining "autowire by type" (bean properties by type) behavior.
BeanWrapper autowireConstructor(String beanName, RootBeanDefinition mbd, Constructor[] ctors, Object[] explicitArgs)
"autowire constructor" (with constructor arguments by type) behavior.
void checkDependencies(String beanName, AbstractBeanDefinition mbd, PropertyDescriptor[] pds, PropertyValues pvs)
Perform a dependency check that all properties exposed have been set, if desired.
Object createBean(String beanName, RootBeanDefinition mbd, Object[] args)
Central method of this class: creates a bean instance, populates the bean instance, applies post-processors, etc.
BeanWrapper createBeanInstance(String beanName, RootBeanDefinition mbd, Object[] args)
Create a new instance for the specified bean, using an appropriate instantiation strategy: factory method, constructor autowiring, or simple instantiation.
Constructor[] determineConstructorsFromBeanPostProcessors(Class beanClass, String beanName)
Determine candidate constructors to use for the given bean, checking all registered SmartInstantiationAwareBeanPostProcessors.
Object doCreateBean(String beanName, RootBeanDefinition mbd, Object[] args)
Actually create the specified bean.
PropertyDescriptor[] filterPropertyDescriptorsForDependencyCheck(BeanWrapper bw)
Extract a filtered set of PropertyDescriptors from the given BeanWrapper, excluding ignored dependency types or properties defined on ignored dependency interfaces.
Object getEarlyBeanReference(String beanName, RootBeanDefinition mbd, Object bean)
Obtain a reference for early access to the specified bean, typically for the purpose of resolving a circular reference.
InstantiationStrategy getInstantiationStrategy()
Return the instantiation strategy to use for creating bean instances.
ParameterNameDiscoverer getParameterNameDiscoverer()
Return the ParameterNameDiscoverer to use for resolving method parameter names if needed.
Class getTypeForFactoryBean(String beanName, RootBeanDefinition mbd)
This implementation checks the FactoryBean's getObjectType method on a plain instance of the FactoryBean, without bean properties applied yet.
Class getTypeForFactoryMethod(String beanName, RootBeanDefinition mbd, Class[] typesToMatch)
Determine the bean type for the given bean definition which is based on a factory method.
Object initializeBean(String beanName, Object bean, RootBeanDefinition mbd)
Initialize the given bean instance, applying factory callbacks as well as init methods and bean post processors.
BeanWrapper instantiateBean(String beanName, RootBeanDefinition mbd)
Instantiate the given bean using its default constructor.
BeanWrapper instantiateUsingFactoryMethod(String beanName, RootBeanDefinition mbd, Object[] explicitArgs)
Instantiate the bean using a named factory method.
void invokeCustomInitMethod(String beanName, Object bean, RootBeanDefinition mbd)
Invoke the specified custom init method on the given bean.
void invokeInitMethods(String beanName, Object bean, RootBeanDefinition mbd)
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).
boolean isExcludedFromDependencyCheck(PropertyDescriptor pd)
Determine whether the given bean property is excluded from dependency checks.
void populateBean(String beanName, AbstractBeanDefinition mbd, BeanWrapper bw)
Populate the bean instance in the given BeanWrapper with the property values from the bean definition.
Object postProcessObjectFromFactoryBean(Object object, String beanName)
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).
Class predictBeanType(String beanName, RootBeanDefinition mbd, Class[] typesToMatch)
Predict the eventual bean type (of the processed bean instance) for the specified bean.
void removeSingleton(String beanName)
Overridden to clear FactoryBean instance cache as well.
Object resolveBeforeInstantiation(String beanName, RootBeanDefinition mbd)
Apply before-instantiation post-processors, resolving whether there is a before-instantiation shortcut for the specified bean.
String[] unsatisfiedNonSimpleProperties(AbstractBeanDefinition mbd, BeanWrapper bw)
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

Public Constructors

public AbstractAutowireCapableBeanFactory ()

Also: SpringBeans

Create a new AbstractAutowireCapableBeanFactory.

public AbstractAutowireCapableBeanFactory (BeanFactory parentBeanFactory)

Also: SpringBeans

Create a new AbstractAutowireCapableBeanFactory with the given parent.

Parameters
parentBeanFactory parent bean factory, or null if none

Public Methods

public Object applyBeanPostProcessorsAfterInitialization (Object existingBean, String beanName)

Also: SpringBeans

Apply BeanPostProcessors to the given existing bean instance, invoking their postProcessAfterInitialization methods. The returned bean instance may be a wrapper around the original.

Parameters
existingBean the new bean instance
beanName the name of the bean
Returns
  • the bean instance to use, either the original or a wrapped one

public Object applyBeanPostProcessorsBeforeInitialization (Object existingBean, String beanName)

Also: SpringBeans

Apply BeanPostProcessors to the given existing bean instance, invoking their postProcessBeforeInitialization methods. The returned bean instance may be a wrapper around the original.

Parameters
existingBean the new bean instance
beanName the name of the bean
Returns
  • the bean instance to use, either the original or a wrapped one

public void applyBeanPropertyValues (Object existingBean, String beanName)

Also: SpringBeans

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.

Parameters
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)

public Object autowire (Class beanClass, int autowireMode, boolean dependencyCheck)

Also: SpringBeans

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.

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 object references in the bean instance (not applicable to autowiring a constructor, thus ignored there)
Returns
  • the new bean instance

public void autowireBean (Object existingBean)

Also: SpringBeans

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.

Parameters
existingBean the existing bean instance

public void autowireBeanProperties (Object existingBean, int autowireMode, boolean dependencyCheck)

Also: SpringBeans

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.

Parameters
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

public Object configureBean (Object existingBean, String beanName)

Also: SpringBeans

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!

Parameters
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)
Returns
  • the bean instance to use, either the original or a wrapped one

public void copyConfigurationFrom (ConfigurableBeanFactory otherFactory)

Also: SpringBeans

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.

Parameters
otherFactory the other BeanFactory to copy from

public T createBean (Class<T> beanClass)

Also: SpringBeans

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.

Parameters
beanClass the class of the bean to create
Returns
  • the new bean instance

public Object createBean (Class beanClass, int autowireMode, boolean dependencyCheck)

Also: SpringBeans

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.

Parameters
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)
Returns
  • the new bean instance

public void ignoreDependencyInterface (Class ifc)

Also: SpringBeans

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.

public void ignoreDependencyType (Class type)

Also: SpringBeans

Ignore the given dependency type for autowiring: for example, String. Default is none.

public Object initializeBean (Object existingBean, String beanName)

Also: SpringBeans

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.

Parameters
existingBean the existing bean instance
beanName the name of the bean, to be passed to it if necessary (only passed to BeanPostProcessors)
Returns
  • the bean instance to use, either the original or a wrapped one

public Object resolveDependency (DependencyDescriptor descriptor, String beanName)

Also: SpringBeans

Resolve the specified dependency against the beans defined in this factory.

Parameters
descriptor the descriptor for the dependency
beanName the name of the bean which declares the present dependency
Returns
  • the resolved object, or null if none found

public void setAllowCircularReferences (boolean allowCircularReferences)

Also: SpringBeans

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.

public void setAllowRawInjectionDespiteWrapping (boolean allowRawInjectionDespiteWrapping)

Also: SpringBeans

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.

public void setInstantiationStrategy (InstantiationStrategy instantiationStrategy)

Also: SpringBeans

Set the instantiation strategy to use for creating bean instances. Default is CglibSubclassingInstantiationStrategy.

public void setParameterNameDiscoverer (ParameterNameDiscoverer parameterNameDiscoverer)

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.

Protected Methods

protected Object applyBeanPostProcessorsBeforeInstantiation (Class beanClass, String beanName)

Also: SpringBeans

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.

Parameters
beanClass the class of the bean to be instantiated
beanName the name of the bean
Returns
  • the bean object to use instead of a default instance of the target bean, or null
Throws
BeansException if any post-processing failed

protected void applyMergedBeanDefinitionPostProcessors (RootBeanDefinition mbd, Class beanType, String beanName)

Also: SpringBeans

Apply MergedBeanDefinitionPostProcessors to the specified bean definition, invoking their postProcessMergedBeanDefinition methods.

Parameters
mbd the merged bean definition for the bean
beanType the actual type of the managed bean instance
beanName the name of the bean
Throws
BeansException if any post-processing failed

protected void applyPropertyValues (String beanName, BeanDefinition mbd, BeanWrapper bw, PropertyValues pvs)

Also: SpringBeans

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.

Parameters
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

protected void autowireByName (String beanName, AbstractBeanDefinition mbd, BeanWrapper bw, MutablePropertyValues pvs)

Also: SpringBeans

Fill in any missing property values with references to other beans in this factory if autowire is set to "byName".

Parameters
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

protected void autowireByType (String beanName, AbstractBeanDefinition mbd, BeanWrapper bw, MutablePropertyValues pvs)

Also: SpringBeans

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.

Parameters
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

protected BeanWrapper autowireConstructor (String beanName, RootBeanDefinition mbd, Constructor[] ctors, Object[] explicitArgs)

Also: SpringBeans

"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.

Parameters
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)
Returns
  • BeanWrapper for the new instance

protected void checkDependencies (String beanName, AbstractBeanDefinition mbd, PropertyDescriptor[] pds, PropertyValues pvs)

Also: SpringBeans

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).

Parameters
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

protected Object createBean (String beanName, RootBeanDefinition mbd, Object[] args)

Also: SpringBeans

Central method of this class: creates a bean instance, populates the bean instance, applies post-processors, etc.

Parameters
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.
Returns
  • a new instance of the bean

protected BeanWrapper createBeanInstance (String beanName, RootBeanDefinition mbd, Object[] args)

Also: SpringBeans

Create a new instance for the specified bean, using an appropriate instantiation strategy: factory method, constructor autowiring, or simple instantiation.

Parameters
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.
Returns
  • BeanWrapper for the new instance

protected Constructor[] determineConstructorsFromBeanPostProcessors (Class beanClass, String beanName)

Also: SpringBeans

Determine candidate constructors to use for the given bean, checking all registered SmartInstantiationAwareBeanPostProcessors.

Parameters
beanClass the raw class of the bean
beanName the name of the bean
Returns
  • the candidate constructors, or null if none specified
Throws
BeansException in case of errors

protected Object doCreateBean (String beanName, RootBeanDefinition mbd, Object[] args)

Also: SpringBeans

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.

Parameters
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.
Returns
  • a new instance of the bean
Throws
BeanCreationException if the bean could not be created

protected PropertyDescriptor[] filterPropertyDescriptorsForDependencyCheck (BeanWrapper bw)

Also: SpringBeans

Extract a filtered set of PropertyDescriptors from the given BeanWrapper, excluding ignored dependency types or properties defined on ignored dependency interfaces.

Parameters
bw the BeanWrapper the bean was created with
Returns
  • the filtered PropertyDescriptors

protected Object getEarlyBeanReference (String beanName, RootBeanDefinition mbd, Object bean)

Also: SpringBeans

Obtain a reference for early access to the specified bean, typically for the purpose of resolving a circular reference.

Parameters
beanName the name of the bean (for error handling purposes)
mbd the merged bean definition for the bean
bean the raw bean instance
Returns
  • the object to expose as bean reference

protected InstantiationStrategy getInstantiationStrategy ()

Also: SpringBeans

Return the instantiation strategy to use for creating bean instances.

protected ParameterNameDiscoverer getParameterNameDiscoverer ()

Also: SpringBeans

Return the ParameterNameDiscoverer to use for resolving method parameter names if needed.

protected Class getTypeForFactoryBean (String beanName, RootBeanDefinition mbd)

Also: SpringBeans

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.

Parameters
beanName the name of the bean
mbd the merged bean definition for the bean
Returns
  • the type for the bean if determinable, or null else

protected Class getTypeForFactoryMethod (String beanName, RootBeanDefinition mbd, Class[] typesToMatch)

Also: SpringBeans

Determine 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.

Parameters
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)
Returns
  • the type for the bean if determinable, or null else

protected Object initializeBean (String beanName, Object bean, RootBeanDefinition mbd)

Also: SpringBeans

Initialize 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.

Parameters
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)
Returns
  • the initialized bean instance (potentially wrapped)

protected BeanWrapper instantiateBean (String beanName, RootBeanDefinition mbd)

Also: SpringBeans

Instantiate the given bean using its default constructor.

Parameters
beanName the name of the bean
mbd the bean definition for the bean
Returns
  • BeanWrapper for the new instance

protected BeanWrapper instantiateUsingFactoryMethod (String beanName, RootBeanDefinition mbd, Object[] explicitArgs)

Also: SpringBeans

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.

Parameters
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)
Returns
  • BeanWrapper for the new instance

protected void invokeCustomInitMethod (String beanName, Object bean, RootBeanDefinition mbd)

Also: SpringBeans

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.

Throws
Throwable

protected void invokeInitMethods (String beanName, Object bean, RootBeanDefinition mbd)

Also: SpringBeans

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.

Parameters
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)
Throws
Throwable if thrown by init methods or by the invocation process

protected boolean isExcludedFromDependencyCheck (PropertyDescriptor pd)

Also: SpringBeans

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.

Parameters
pd the PropertyDescriptor of the bean property
Returns
  • whether the bean property is excluded

protected void populateBean (String beanName, AbstractBeanDefinition mbd, BeanWrapper bw)

Also: SpringBeans

Populate the bean instance in the given BeanWrapper with the property values from the bean definition.

Parameters
beanName the name of the bean
mbd the bean definition for the bean
bw BeanWrapper with bean instance

protected Object postProcessObjectFromFactoryBean (Object object, String beanName)

Also: SpringBeans

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).

Parameters
object the object obtained from the FactoryBean.
beanName the name of the bean
Returns
  • the object to expose

protected Class predictBeanType (String beanName, RootBeanDefinition mbd, Class[] typesToMatch)

Also: SpringBeans

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.

Parameters
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)
Returns
  • the type of the bean, or null if not predictable

protected void removeSingleton (String beanName)

Also: SpringBeans

Overridden to clear FactoryBean instance cache as well.

Parameters
beanName the name of the bean

protected Object resolveBeforeInstantiation (String beanName, RootBeanDefinition mbd)

Also: SpringBeans

Apply before-instantiation post-processors, resolving whether there is a before-instantiation shortcut for the specified bean.

Parameters
beanName the name of the bean
mbd the bean definition for the bean
Returns
  • the shortcut-determined bean instance, or null if none

protected String[] unsatisfiedNonSimpleProperties (AbstractBeanDefinition mbd, BeanWrapper bw)

Also: SpringBeans

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.

Parameters
mbd the merged bean definition the bean was created with
bw the BeanWrapper the bean was created with
Returns
  • an array of bean property names