|
|||||||||||
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 BeanFactory 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, used for autowiring by type. Note that this class does not implement bean definition registry capabilities (DefaultListableBeanFactory does).
findMatchingBeans(java.lang.Class)
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()
|
|
AbstractAutowireCapableBeanFactory(BeanFactory parentBeanFactory)
|
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. |
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) behaviour. |
protected BeanWrapper |
autowireConstructor(java.lang.String beanName,
RootBeanDefinition mergedBeanDefinition)
"autowire constructor" (with constructor arguments by type) behaviour. |
protected java.lang.Object |
createBean(java.lang.String beanName,
RootBeanDefinition mergedBeanDefinition)
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 abstract java.lang.String[] |
getDependingBeanNames(java.lang.String beanName)
Return the names of the beans that depend on the given bean. |
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 |
invokeInitMethods(java.lang.Object bean,
java.lang.String beanName,
RootBeanDefinition mergedBeanDefinition)
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 java.util.List |
resolveManagedList(java.lang.String beanName,
RootBeanDefinition mergedBeanDefinition,
java.lang.String argName,
ManagedList 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,
ManagedMap 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,
ManagedSet ms)
For each element in the ManagedList, resolve reference if necessary. |
protected java.lang.Object |
resolveReference(RootBeanDefinition mergedBeanDefinition,
java.lang.String beanName,
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 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, getBeanDefinition, getBeanPostProcessors, getCustomEditors, getIgnoredDependencyTypes, getMergedBeanDefinition, getMergedBeanDefinition, getObjectForSharedInstance, getParentBeanFactory, getSingletonNames, ignoreDependencyType, initBeanWrapper, isFactoryDereference, isSingleton, registerAlias, registerCustomEditor, registerSingleton, 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)
Method Detail |
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 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) throws BeansException
AbstractBeanFactory
All the other methods in this class invoke this method, although beans may be cached after being instantiated by this method. All bean instantiation within this class is performed by this method.
createBean
in class AbstractBeanFactory
beanName
- name of the beanmergedBeanDefinition
- the bean definition for the bean
BeansException
- in case of errorsprotected BeanWrapper autowireConstructor(java.lang.String beanName, RootBeanDefinition mergedBeanDefinition) throws BeansException
This corresponds to PicoContainer's "Type 3 IoC" paradigm: 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)
beanName
- name of the beanmergedBeanDefinition
- the bean definition for the beanbw
- BeanWrapper with bean instanceprotected void autowireByName(java.lang.String beanName, RootBeanDefinition mergedBeanDefinition, BeanWrapper bw, MutablePropertyValues pvs)
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 withprotected void autowireByType(java.lang.String beanName, RootBeanDefinition mergedBeanDefinition, BeanWrapper bw, MutablePropertyValues pvs)
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 behaviour 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 withprotected 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 resolveReference(RootBeanDefinition mergedBeanDefinition, java.lang.String beanName, java.lang.String argName, RuntimeBeanReference ref) throws BeansException
BeansException
protected java.util.List resolveManagedList(java.lang.String beanName, RootBeanDefinition mergedBeanDefinition, java.lang.String argName, ManagedList ml) throws BeansException
BeansException
protected java.util.Set resolveManagedSet(java.lang.String beanName, RootBeanDefinition mergedBeanDefinition, java.lang.String argName, ManagedSet ms) throws BeansException
BeansException
protected java.util.Map resolveManagedMap(java.lang.String beanName, RootBeanDefinition mergedBeanDefinition, java.lang.String argName, ManagedMap mm) throws BeansException
BeansException
protected void invokeInitMethods(java.lang.Object bean, java.lang.String beanName, RootBeanDefinition mergedBeanDefinition) throws java.lang.Exception
bean
- new bean instance we may need to initializebeanName
- the bean has in the factory. Used for debug output.
java.lang.Exception
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)
protected abstract java.lang.String[] getDependingBeanNames(java.lang.String beanName) throws BeansException
beanName
- name of the bean to find depending beans for
BeansException
- in case of errorsdestroyBean(java.lang.String, java.lang.Object)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |