public interface AutowireCapableBeanFactory extends BeanFactory
BeanFactory
interface to be implemented by bean factories that are capable of
autowiring, provided that they want to expose this functionality for
existing bean instances.
This subinterface of BeanFactory is not meant to be used in normal
application code: stick to BeanFactory
or ListableBeanFactory
for
typical use cases.
Integration code for other frameworks can leverage this interface to wire and populate existing bean instances that Spring does not control the lifecycle of. This is particularly useful for WebWork Actions and Tapestry Page objects, for example.
Note that this interface is not implemented by
ApplicationContext
facades,
as it is hardly ever used by application code. That said, it is available
from an application context too, accessible through ApplicationContext's
ApplicationContext.getAutowireCapableBeanFactory()
method.
You may also implement the BeanFactoryAware
interface, which exposes the internal BeanFactory even when running in an
ApplicationContext, to get access to an AutowireCapableBeanFactory:
simply cast the passed-in BeanFactory to AutowireCapableBeanFactory.
BeanFactoryAware
,
ConfigurableListableBeanFactory
,
ApplicationContext.getAutowireCapableBeanFactory()
Modifier and Type | Field and Description |
---|---|
static int |
AUTOWIRE_AUTODETECT
Deprecated.
as of Spring 3.0: If you are using mixed autowiring strategies,
prefer annotation-based autowiring for clearer demarcation of autowiring needs.
|
static int |
AUTOWIRE_BY_NAME
Constant that indicates autowiring bean properties by name
(applying to all bean property setters).
|
static int |
AUTOWIRE_BY_TYPE
Constant that indicates autowiring bean properties by type
(applying to all bean property setters).
|
static int |
AUTOWIRE_CONSTRUCTOR
Constant that indicates autowiring the greediest constructor that
can be satisfied (involves resolving the appropriate constructor).
|
static int |
AUTOWIRE_NO
Constant that indicates no externally defined autowiring.
|
static java.lang.String |
ORIGINAL_INSTANCE_SUFFIX
Suffix for the "original instance" convention when initializing an existing
bean instance: to be appended to the fully-qualified bean class name,
e.g.
|
FACTORY_BEAN_PREFIX
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
applyBeanPostProcessorsAfterInitialization(java.lang.Object existingBean,
java.lang.String beanName)
Apply
BeanPostProcessors to the given existing bean
instance, invoking their postProcessAfterInitialization methods. |
java.lang.Object |
applyBeanPostProcessorsBeforeInitialization(java.lang.Object existingBean,
java.lang.String beanName)
Apply
BeanPostProcessors to the given existing bean
instance, invoking their postProcessBeforeInitialization methods. |
void |
applyBeanPropertyValues(java.lang.Object existingBean,
java.lang.String beanName)
Apply the property values of the bean definition with the given name to
the given bean instance.
|
java.lang.Object |
autowire(java.lang.Class<?> beanClass,
int autowireMode,
boolean dependencyCheck)
Instantiate a new bean instance of the given class with the specified autowire
strategy.
|
void |
autowireBean(java.lang.Object existingBean)
Populate the given bean instance through applying after-instantiation callbacks
and bean property post-processing (e.g.
|
void |
autowireBeanProperties(java.lang.Object existingBean,
int autowireMode,
boolean dependencyCheck)
Autowire the bean properties of the given bean instance by name or type.
|
java.lang.Object |
configureBean(java.lang.Object existingBean,
java.lang.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). |
java.lang.Object |
createBean(java.lang.Class<?> beanClass,
int autowireMode,
boolean dependencyCheck)
Fully create a new bean instance of the given class with the specified
autowire strategy.
|
<T> T |
createBean(java.lang.Class<T> beanClass)
Fully create a new bean instance of the given class.
|
void |
destroyBean(java.lang.Object existingBean)
Destroy the given bean instance (typically coming from
createBean(java.lang.Class<T>) ),
applying the DisposableBean contract as well as
registered DestructionAwareBeanPostProcessors . |
java.lang.Object |
initializeBean(java.lang.Object existingBean,
java.lang.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). |
java.lang.Object |
resolveDependency(DependencyDescriptor descriptor,
java.lang.String requestingBeanName)
Resolve the specified dependency against the beans defined in this factory.
|
java.lang.Object |
resolveDependency(DependencyDescriptor descriptor,
java.lang.String requestingBeanName,
java.util.Set<java.lang.String> autowiredBeanNames,
TypeConverter typeConverter)
Resolve the specified dependency against the beans defined in this factory.
|
<T> NamedBeanHolder<T> |
resolveNamedBean(java.lang.Class<T> requiredType)
Resolve the bean instance that uniquely matches the given object type, if any,
including its bean name.
|
containsBean, getAliases, getBean, getBean, getBean, getBean, getBean, getBeanProvider, getBeanProvider, getType, isPrototype, isSingleton, isTypeMatch, isTypeMatch
static final int AUTOWIRE_NO
static final int AUTOWIRE_BY_NAME
static final int AUTOWIRE_BY_TYPE
static final int AUTOWIRE_CONSTRUCTOR
@Deprecated static final int AUTOWIRE_AUTODETECT
static final java.lang.String ORIGINAL_INSTANCE_SUFFIX
<T> T createBean(java.lang.Class<T> beanClass) throws BeansException
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 initialization callbacks.
It does not imply traditional by-name or by-type autowiring of properties;
use createBean(Class, int, boolean)
for those purposes.
beanClass
- the class of the bean to createBeansException
- if instantiation or wiring failedvoid autowireBean(java.lang.Object existingBean) throws BeansException
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(java.lang.Object, int, boolean)
for those purposes.
existingBean
- the existing bean instanceBeansException
- if wiring failedjava.lang.Object configureBean(java.lang.Object existingBean, java.lang.String beanName) throws BeansException
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(java.lang.Object, java.lang.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 instancebeanName
- the name of the bean, to be passed to it if necessary
(a bean definition of that name has to be available)NoSuchBeanDefinitionException
- if there is no bean definition with the given nameBeansException
- if the initialization failedinitializeBean(java.lang.Object, java.lang.String)
java.lang.Object createBean(java.lang.Class<?> beanClass, int autowireMode, boolean dependencyCheck) throws BeansException
Performs full initialization of the bean, including all applicable
BeanPostProcessors
. This is effectively a superset
of what autowire(java.lang.Class<?>, int, boolean)
provides, adding initializeBean(java.lang.Object, java.lang.String)
behavior.
beanClass
- the class of the bean to createautowireMode
- 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 or wiring failedAUTOWIRE_NO
,
AUTOWIRE_BY_NAME
,
AUTOWIRE_BY_TYPE
,
AUTOWIRE_CONSTRUCTOR
java.lang.Object autowire(java.lang.Class<?> beanClass, int autowireMode, boolean dependencyCheck) throws BeansException
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(java.lang.Object, java.lang.String)
. However, InstantiationAwareBeanPostProcessor
callbacks are applied, if applicable to the construction of the instance.
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 object
references in the bean instance (not applicable to autowiring a constructor,
thus ignored there)BeansException
- if instantiation or wiring failedAUTOWIRE_NO
,
AUTOWIRE_BY_NAME
,
AUTOWIRE_BY_TYPE
,
AUTOWIRE_CONSTRUCTOR
,
AUTOWIRE_AUTODETECT
,
initializeBean(java.lang.Object, java.lang.String)
,
applyBeanPostProcessorsBeforeInitialization(java.lang.Object, java.lang.String)
,
applyBeanPostProcessorsAfterInitialization(java.lang.Object, java.lang.String)
void autowireBeanProperties(java.lang.Object existingBean, int autowireMode, boolean dependencyCheck) throws BeansException
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(java.lang.Object, java.lang.String)
. However, InstantiationAwareBeanPostProcessor
callbacks are applied, if applicable to the configuration of the instance.
existingBean
- the existing bean instanceautowireMode
- by name or type, using the constants in this interfacedependencyCheck
- whether to perform a dependency check for object
references in the bean instanceBeansException
- if wiring failedAUTOWIRE_BY_NAME
,
AUTOWIRE_BY_TYPE
,
AUTOWIRE_NO
void applyBeanPropertyValues(java.lang.Object existingBean, java.lang.String beanName) throws BeansException
This method does not autowire bean properties; it just applies
explicitly defined property values. Use the autowireBeanProperties(java.lang.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(java.lang.Object, java.lang.String)
. However, InstantiationAwareBeanPostProcessor
callbacks are applied, if applicable to the configuration of the instance.
existingBean
- the existing bean instancebeanName
- the name of the bean definition in the bean factory
(a bean definition of that name has to be available)NoSuchBeanDefinitionException
- if there is no bean definition with the given nameBeansException
- if applying the property values failedautowireBeanProperties(java.lang.Object, int, boolean)
java.lang.Object initializeBean(java.lang.Object existingBean, java.lang.String beanName) throws BeansException
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 instancebeanName
- the name of the bean, to be passed to it if necessary
(only passed to BeanPostProcessors
;
can follow the ORIGINAL_INSTANCE_SUFFIX
convention in order to
enforce the given instance to be returned, i.e. no proxies etc)BeansException
- if the initialization failedORIGINAL_INSTANCE_SUFFIX
java.lang.Object applyBeanPostProcessorsBeforeInitialization(java.lang.Object existingBean, java.lang.String beanName) throws BeansException
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
(only passed to BeanPostProcessors
;
can follow the ORIGINAL_INSTANCE_SUFFIX
convention in order to
enforce the given instance to be returned, i.e. no proxies etc)BeansException
- if any post-processing failedBeanPostProcessor.postProcessBeforeInitialization(java.lang.Object, java.lang.String)
,
ORIGINAL_INSTANCE_SUFFIX
java.lang.Object applyBeanPostProcessorsAfterInitialization(java.lang.Object existingBean, java.lang.String beanName) throws BeansException
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
(only passed to BeanPostProcessors
;
can follow the ORIGINAL_INSTANCE_SUFFIX
convention in order to
enforce the given instance to be returned, i.e. no proxies etc)BeansException
- if any post-processing failedBeanPostProcessor.postProcessAfterInitialization(java.lang.Object, java.lang.String)
,
ORIGINAL_INSTANCE_SUFFIX
void destroyBean(java.lang.Object existingBean)
createBean(java.lang.Class<T>)
),
applying the DisposableBean
contract as well as
registered DestructionAwareBeanPostProcessors
.
Any exception that arises during destruction should be caught and logged instead of propagated to the caller of this method.
existingBean
- the bean instance to destroy<T> NamedBeanHolder<T> resolveNamedBean(java.lang.Class<T> requiredType) throws BeansException
This is effectively a variant of BeanFactory.getBean(Class)
which preserves the
bean name of the matching instance.
requiredType
- type the bean must match; can be an interface or superclass.
null
is disallowed.NoSuchBeanDefinitionException
- if no matching bean was foundNoUniqueBeanDefinitionException
- if more than one matching bean was foundBeansException
- if the bean could not be createdBeanFactory.getBean(Class)
@Nullable java.lang.Object resolveDependency(DependencyDescriptor descriptor, @Nullable java.lang.String requestingBeanName) throws BeansException
descriptor
- the descriptor for the dependency (field/method/constructor)requestingBeanName
- the name of the bean which declares the given dependencynull
if none foundNoSuchBeanDefinitionException
- if no matching bean was foundNoUniqueBeanDefinitionException
- if more than one matching bean was foundBeansException
- if dependency resolution failed for any other reasonresolveDependency(DependencyDescriptor, String, Set, TypeConverter)
@Nullable java.lang.Object resolveDependency(DependencyDescriptor descriptor, @Nullable java.lang.String requestingBeanName, @Nullable java.util.Set<java.lang.String> autowiredBeanNames, @Nullable TypeConverter typeConverter) throws BeansException
descriptor
- the descriptor for the dependency (field/method/constructor)requestingBeanName
- the name of the bean which declares the given dependencyautowiredBeanNames
- a Set that all names of autowired beans (used for
resolving the given dependency) are supposed to be added totypeConverter
- the TypeConverter to use for populating arrays and collectionsnull
if none foundNoSuchBeanDefinitionException
- if no matching bean was foundNoUniqueBeanDefinitionException
- if more than one matching bean was foundBeansException
- if dependency resolution failed for any other reasonDependencyDescriptor