|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.beans.factory.support.AbstractBeanFactory org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
Abstract bean factory superclass that implements default bean creation. Implements the AutowireCapableBeanFactory interface.
Provides bean creation, initialization and wiring, supporting autowiring and constructor resolution. Handles runtime bean references, managed collections, and bean destruction.
The main template method to be implemented by subclasses is findMatchingBeans
not implement bean definition
registry capabilities (DefaultListableBeanFactory does).
findMatchingBeans(java.lang.Class)
,
DefaultListableBeanFactory
Field Summary |
Fields inherited from class org.springframework.beans.factory.support.AbstractBeanFactory |
FACTORY_BEAN_PREFIX, logger |
Fields inherited from interface org.springframework.beans.factory.config.AutowireCapableBeanFactory |
AUTOWIRE_AUTODETECT, AUTOWIRE_BY_NAME, AUTOWIRE_BY_TYPE, AUTOWIRE_CONSTRUCTOR |
Constructor Summary | |
AbstractAutowireCapableBeanFactory()
Create a new AbstractAutowireCapableBeanFactory. |
|
AbstractAutowireCapableBeanFactory(BeanFactory parentBeanFactory)
Create a new AbstractAutowireCapableBeanFactory with the given parent. |
Method Summary | |
java.lang.Object |
applyBeanPostProcessorsAfterInitialization(java.lang.Object bean,
java.lang.String name)
Apply BeanPostProcessors to the given existing bean instance, invoking their postProcessAfterInitialization methods. |
java.lang.Object |
applyBeanPostProcessorsBeforeInitialization(java.lang.Object bean,
java.lang.String name)
Apply BeanPostProcessors to the given existing bean instance, invoking their postProcessBeforeInitialization methods. |
void |
applyBeanPropertyValues(java.lang.Object existingBean,
java.lang.String name)
Apply the property values of the bean definition with the given name to the given bean instance. |
protected void |
applyPropertyValues(java.lang.String beanName,
RootBeanDefinition mergedBeanDefinition,
BeanWrapper bw,
PropertyValues pvs)
Apply the given property values, resolving any runtime references to other beans in this bean factory. |
java.lang.Object |
autowire(java.lang.Class beanClass,
int autowireMode,
boolean dependencyCheck)
Create a new bean instance of the given class with the specified autowire strategy. |
void |
autowireBeanProperties(java.lang.Object existingBean,
int autowireMode,
boolean dependencyCheck)
Autowire the bean properties of the given bean instance by name or type. |
protected void |
autowireByName(java.lang.String beanName,
RootBeanDefinition mergedBeanDefinition,
BeanWrapper bw,
MutablePropertyValues pvs)
Fills in any missing property values with references to other beans in this factory if autowire is set to "byName". |
protected void |
autowireByType(java.lang.String beanName,
RootBeanDefinition mergedBeanDefinition,
BeanWrapper bw,
MutablePropertyValues pvs)
Abstract method defining "autowire by type" (bean properties by type) behavior. |
protected BeanWrapper |
autowireConstructor(java.lang.String beanName,
RootBeanDefinition mergedBeanDefinition)
"autowire constructor" (with constructor arguments by type) behavior. |
protected java.lang.Object |
createBean(java.lang.String beanName,
RootBeanDefinition mergedBeanDefinition,
java.lang.Object[] args)
Delegates to full createBean version with allowEagerCaching=true. |
protected java.lang.Object |
createBean(java.lang.String beanName,
RootBeanDefinition mergedBeanDefinition,
java.lang.Object[] args,
boolean allowEagerCaching)
Create a bean instance for the given bean definition. |
protected void |
dependencyCheck(java.lang.String beanName,
RootBeanDefinition mergedBeanDefinition,
BeanWrapper bw,
PropertyValues pvs)
Perform a dependency check that all properties exposed have been set, if desired. |
protected void |
destroyBean(java.lang.String beanName,
java.lang.Object bean)
Destroy the given bean. |
void |
destroySingletons()
Destroy all cached singletons in this factory. |
protected abstract java.util.Map |
findMatchingBeans(java.lang.Class requiredType)
Find bean instances that match the required type. |
protected BeanWrapper |
instantiateUsingFactoryMethod(java.lang.String beanName,
RootBeanDefinition mergedBeanDefinition,
java.lang.Object[] args)
Instantiate the bean using a named factory method. |
protected void |
invokeCustomDestroyMethod(java.lang.String beanName,
java.lang.Object bean,
java.lang.String destroyMethodName)
Invoke the specified custom destroy method on the given bean. |
protected void |
invokeCustomInitMethod(java.lang.String beanName,
java.lang.Object bean,
java.lang.String initMethodName,
java.lang.String resourceDescription)
Invoke the specified custom init method on the given bean. |
protected void |
invokeInitMethods(java.lang.String beanName,
RootBeanDefinition mergedBeanDefinition,
java.lang.Object 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). |
protected void |
populateBean(java.lang.String beanName,
RootBeanDefinition mergedBeanDefinition,
BeanWrapper bw)
Populate the bean instance in the given BeanWrapper with the property values from the bean definition. |
protected void |
registerDependentBean(java.lang.String beanName,
java.lang.String dependentBeanName)
Register a dependent bean for the given bean, to be destroyed before the given bean is destroyed. |
protected java.lang.Object |
resolveInnerBeanDefinition(java.lang.String beanName,
java.lang.String innerBeanName,
BeanDefinition innerBd)
Resolve an inner bean definition. |
protected java.util.List |
resolveManagedList(java.lang.String beanName,
RootBeanDefinition mergedBeanDefinition,
java.lang.String argName,
java.util.List ml)
For each element in the ManagedList, resolve reference if necessary. |
protected java.util.Map |
resolveManagedMap(java.lang.String beanName,
RootBeanDefinition mergedBeanDefinition,
java.lang.String argName,
java.util.Map mm)
For each element in the ManagedMap, resolve reference if necessary. |
protected java.util.Set |
resolveManagedSet(java.lang.String beanName,
RootBeanDefinition mergedBeanDefinition,
java.lang.String argName,
java.util.Set ms)
For each element in the ManagedList, resolve reference if necessary. |
protected java.lang.Object |
resolveReference(java.lang.String beanName,
RootBeanDefinition mergedBeanDefinition,
java.lang.String argName,
RuntimeBeanReference ref)
Resolve a reference to another bean in the factory. |
protected java.lang.Object |
resolveValueIfNecessary(java.lang.String beanName,
RootBeanDefinition mergedBeanDefinition,
java.lang.String argName,
java.lang.Object value)
Given a PropertyValue, return a value, resolving any references to other beans in the factory if necessary. |
protected void |
setInstantiationStrategy(InstantiationStrategy instantiationStrategy)
Set the instantiation strategy to use. |
protected java.lang.String[] |
unsatisfiedObjectProperties(RootBeanDefinition mergedBeanDefinition,
BeanWrapper bw)
Return an array of object-type property names that are unsatisfied. |
Methods inherited from class org.springframework.beans.factory.support.AbstractBeanFactory |
addBeanPostProcessor, addSingleton, containsBean, containsBeanDefinition, destroySingleton, getAliases, getBean, getBean, getBean, getBeanDefinition, getBeanPostProcessors, getCustomEditors, getIgnoredDependencyTypes, getMergedBeanDefinition, getMergedBeanDefinition, getObjectForSharedInstance, getParentBeanFactory, getSingletonNames, ignoreDependencyType, initBeanWrapper, isFactoryDereference, isSingleton, registerAlias, registerCustomEditor, registerSingleton, removeSingleton, setParentBeanFactory, transformedBeanName |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.springframework.beans.factory.BeanFactory |
containsBean, getAliases, getBean, getBean, isSingleton |
Constructor Detail |
public AbstractAutowireCapableBeanFactory()
public AbstractAutowireCapableBeanFactory(BeanFactory parentBeanFactory)
parentBeanFactory
- parent bean factory, or null if noneMethod Detail |
protected void setInstantiationStrategy(InstantiationStrategy instantiationStrategy)
CglibSubclassingInstantiationStrategy
public java.lang.Object autowire(java.lang.Class beanClass, int autowireMode, boolean dependencyCheck) throws BeansException
AutowireCapableBeanFactory
autowire
in interface AutowireCapableBeanFactory
beanClass
- the class of the bean to instantiateautowireMode
- by name or type, using the constants in this interfacedependencyCheck
- whether to perform a dependency check for objects
(not applicable to autowiring a constructor, thus ignored there)
BeansException
- if instantiation respectively wiring failedAutowireCapableBeanFactory.AUTOWIRE_BY_NAME
,
AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE
,
AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR
,
AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT
public void autowireBeanProperties(java.lang.Object existingBean, int autowireMode, boolean dependencyCheck) throws BeansException
AutowireCapableBeanFactory
autowireBeanProperties
in interface AutowireCapableBeanFactory
existingBean
- the existing bean instanceautowireMode
- by name or type, using the constants in this interfacedependencyCheck
- whether to perform a dependency check for object
BeansException
- if wiring failedAutowireCapableBeanFactory.AUTOWIRE_BY_NAME
,
AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE
public void applyBeanPropertyValues(java.lang.Object existingBean, java.lang.String name) throws BeansException
AutowireCapableBeanFactory
applyBeanPropertyValues
in interface AutowireCapableBeanFactory
existingBean
- the existing bean instancename
- the name of the bean definition in the bean factory
BeansException
- if applying the property values failedpublic java.lang.Object applyBeanPostProcessorsBeforeInitialization(java.lang.Object bean, java.lang.String name) throws BeansException
AutowireCapableBeanFactory
applyBeanPostProcessorsBeforeInitialization
in interface AutowireCapableBeanFactory
bean
- the new bean instancename
- the name of the bean
BeansException
- if any post-processing failedBeanPostProcessor.postProcessBeforeInitialization(java.lang.Object, java.lang.String)
public java.lang.Object applyBeanPostProcessorsAfterInitialization(java.lang.Object bean, java.lang.String name) throws BeansException
AutowireCapableBeanFactory
applyBeanPostProcessorsAfterInitialization
in interface AutowireCapableBeanFactory
bean
- the new bean instancename
- the name of the bean
BeansException
- if any post-processing failedBeanPostProcessor.postProcessAfterInitialization(java.lang.Object, java.lang.String)
protected java.lang.Object createBean(java.lang.String beanName, RootBeanDefinition mergedBeanDefinition, java.lang.Object[] args) throws BeansException
createBean
in class AbstractBeanFactory
beanName
- name of the beanmergedBeanDefinition
- the bean definition for the beanargs
- arguments to use if creating a prototype using explicit arguments
to a static factory method. This parameter must be null except in this case.
BeansException
- in case of errorscreateBean(String, RootBeanDefinition, Object[], boolean)
protected java.lang.Object createBean(java.lang.String beanName, RootBeanDefinition mergedBeanDefinition, java.lang.Object[] args, boolean allowEagerCaching) throws BeansException
beanName
- name of the beanmergedBeanDefinition
- the bean definition for the beanallowEagerCaching
- whether eager caching of singletons is allowed
(typically true for normal beans, but false for inner beans)args
- arguments to use if this is a prototype constructed by a factory method.
In this case, this will override any args specified in the bean definitions.
This parameter should be null otherwise.
BeansException
- in case of errorsprotected BeanWrapper instantiateUsingFactoryMethod(java.lang.String beanName, RootBeanDefinition mergedBeanDefinition, java.lang.Object[] args) throws BeansException
Implementation requires iterating over the static or instance methods with the name specified in the RootBeanDefinition (the method may be overloaded) and trying to match with the parameters. We don't have the types attached to constructor args, so trial and error is the only way to go here. The args array may contain argument values passed in programmatically via the overloaded getBean() method.
BeansException
protected BeanWrapper autowireConstructor(java.lang.String beanName, RootBeanDefinition mergedBeanDefinition) throws BeansException
This corresponds to constructor injection: In this mode, a Spring bean factory is able to host components that expect constructor-based dependency resolution.
beanName
- name of the bean to autowire by typemergedBeanDefinition
- bean definition to update through autowiring
BeansException
protected void populateBean(java.lang.String beanName, RootBeanDefinition mergedBeanDefinition, BeanWrapper bw) throws BeansException
beanName
- name of the beanmergedBeanDefinition
- the bean definition for the beanbw
- BeanWrapper with bean instance
BeansException
protected void autowireByName(java.lang.String beanName, RootBeanDefinition mergedBeanDefinition, BeanWrapper bw, MutablePropertyValues pvs) throws BeansException
beanName
- name of the bean we're wiring up.
Useful for debugging messages; not used functionally.mergedBeanDefinition
- bean definition to update through autowiringbw
- BeanWrapper from which we can obtain information about the beanpvs
- the PropertyValues to register wired objects with
BeansException
protected void autowireByType(java.lang.String beanName, RootBeanDefinition mergedBeanDefinition, BeanWrapper bw, MutablePropertyValues pvs) throws BeansException
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
- name of the bean to autowire by typemergedBeanDefinition
- bean definition to update through autowiringbw
- BeanWrapper from which we can obtain information about the beanpvs
- the PropertyValues to register wired objects with
BeansException
protected void dependencyCheck(java.lang.String beanName, RootBeanDefinition mergedBeanDefinition, BeanWrapper bw, PropertyValues pvs) throws UnsatisfiedDependencyException
beanName
- name of the bean
UnsatisfiedDependencyException
protected java.lang.String[] unsatisfiedObjectProperties(RootBeanDefinition mergedBeanDefinition, BeanWrapper bw)
BeanUtils.isSimpleProperty(java.lang.Class)
protected void applyPropertyValues(java.lang.String beanName, RootBeanDefinition mergedBeanDefinition, BeanWrapper bw, PropertyValues pvs) throws BeansException
beanName
- bean name passed for better exception informationbw
- BeanWrapper wrapping the target objectpvs
- new property values
BeansException
protected java.lang.Object resolveValueIfNecessary(java.lang.String beanName, RootBeanDefinition mergedBeanDefinition, java.lang.String argName, java.lang.Object value) throws BeansException
BeansException
protected java.lang.Object resolveInnerBeanDefinition(java.lang.String beanName, java.lang.String innerBeanName, BeanDefinition innerBd) throws BeansException
BeansException
protected java.lang.Object resolveReference(java.lang.String beanName, RootBeanDefinition mergedBeanDefinition, java.lang.String argName, RuntimeBeanReference ref) throws BeansException
BeansException
protected java.util.List resolveManagedList(java.lang.String beanName, RootBeanDefinition mergedBeanDefinition, java.lang.String argName, java.util.List ml) throws BeansException
BeansException
protected java.util.Set resolveManagedSet(java.lang.String beanName, RootBeanDefinition mergedBeanDefinition, java.lang.String argName, java.util.Set ms) throws BeansException
BeansException
protected java.util.Map resolveManagedMap(java.lang.String beanName, RootBeanDefinition mergedBeanDefinition, java.lang.String argName, java.util.Map mm) throws BeansException
BeansException
protected final void registerDependentBean(java.lang.String beanName, java.lang.String dependentBeanName)
beanName
- the name of the beandependentBeanName
- the name of the dependent beanprotected void invokeInitMethods(java.lang.String beanName, RootBeanDefinition mergedBeanDefinition, java.lang.Object bean) throws java.lang.Throwable
bean
- new bean instance we may need to initializebeanName
- the bean has in the factory. Used for debug output.
java.lang.Throwable
- if thrown by init methods or by the invocation processprotected void invokeCustomInitMethod(java.lang.String beanName, java.lang.Object bean, java.lang.String initMethodName, java.lang.String resourceDescription) throws java.lang.Throwable
Can be overridden in subclasses for custom resolution of init methods with arguments.
java.lang.Throwable
public void destroySingletons()
ConfigurableBeanFactory
destroySingletons
in interface ConfigurableBeanFactory
destroySingletons
in class AbstractBeanFactory
protected void destroyBean(java.lang.String beanName, java.lang.Object bean)
AbstractBeanFactory
destroyBean
in class AbstractBeanFactory
beanName
- name of the beanbean
- the bean instance to destroyprotected void invokeCustomDestroyMethod(java.lang.String beanName, java.lang.Object bean, java.lang.String destroyMethodName)
This implementation invokes a no-arg method if found, else checking for a method with a single boolean argument (passing in "true", assuming a "force" parameter), else logging an error.
Can be overridden in subclasses for custom resolution of destroy methods with arguments.
protected abstract java.util.Map findMatchingBeans(java.lang.Class requiredType) throws BeansException
requiredType
- the type of the beans to look up
BeansException
- in case of errorsautowireByType(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition, org.springframework.beans.BeanWrapper, org.springframework.beans.MutablePropertyValues)
,
autowireConstructor(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |