|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface AutowireCapableBeanFactory
Extension of the 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()
Field Summary | |
---|---|
static int |
AUTOWIRE_AUTODETECT
Constant that indicates determining an appropriate autowire strategy through introspection of the bean class. |
static int |
AUTOWIRE_BY_NAME
Constant that indicates autowiring bean properties by name. |
static int |
AUTOWIRE_BY_TYPE
Constant that indicates autowiring bean properties by type. |
static int |
AUTOWIRE_CONSTRUCTOR
Constant that indicates autowiring a constructor. |
static int |
AUTOWIRE_NO
Constant that indicates no autowiring at all (other than callbacks such as BeanFactoryAware). |
Fields inherited from interface org.springframework.beans.factory.BeanFactory |
---|
FACTORY_BEAN_PREFIX |
Method Summary | |
---|---|
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 |
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 bean instance: autowiring bean properties, applying bean property values, applying factory callbacks such as setBeanName
and setBeanFactory , and also applying all bean post processors. |
Object |
createBean(Class beanClass,
int autowireMode,
boolean dependencyCheck)
Fully create a new bean instance of the given class with the specified autowire strategy. |
Object |
initializeBean(Object existingBean,
String beanName)
Initialize the given bean instance, applying factory callbacks such as setBeanName and setBeanFactory ,
also applying all bean post processors. |
Methods inherited from interface org.springframework.beans.factory.BeanFactory |
---|
containsBean, getAliases, getBean, getBean, getType, isPrototype, isSingleton, isTypeMatch |
Field Detail |
---|
static final int AUTOWIRE_NO
createBean(java.lang.Class, int, boolean)
,
autowire(java.lang.Class, int, boolean)
,
autowireBeanProperties(java.lang.Object, int, boolean)
,
Constant Field Valuesstatic final int AUTOWIRE_BY_NAME
createBean(java.lang.Class, int, boolean)
,
autowire(java.lang.Class, int, boolean)
,
autowireBeanProperties(java.lang.Object, int, boolean)
,
Constant Field Valuesstatic final int AUTOWIRE_BY_TYPE
createBean(java.lang.Class, int, boolean)
,
autowire(java.lang.Class, int, boolean)
,
autowireBeanProperties(java.lang.Object, int, boolean)
,
Constant Field Valuesstatic final int AUTOWIRE_CONSTRUCTOR
createBean(java.lang.Class, int, boolean)
,
autowire(java.lang.Class, int, boolean)
,
Constant Field Valuesstatic final int AUTOWIRE_AUTODETECT
createBean(java.lang.Class, int, boolean)
,
autowire(java.lang.Class, int, boolean)
,
Constant Field ValuesMethod Detail |
---|
Object createBean(Class beanClass, int autowireMode, boolean dependencyCheck) throws BeansException
Performs full initialization of the bean, including all applicable
BeanPostProcessors
.
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
,
AUTOWIRE_AUTODETECT
Object autowire(Class beanClass, int autowireMode, boolean dependencyCheck) throws BeansException
Does not apply any BeanPostProcessors
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)
.
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(Object existingBean, int autowireMode, boolean dependencyCheck) throws BeansException
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 instance
BeansException
- if wiring failedAUTOWIRE_BY_NAME
,
AUTOWIRE_BY_TYPE
void applyBeanPropertyValues(Object existingBean, String beanName) throws BeansException
Note: 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.
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 with the given name
BeansException
- if applying the property values failedautowireBeanProperties(java.lang.Object, int, boolean)
Object configureBean(Object existingBean, String beanName) throws BeansException
setBeanName
and setBeanFactory
, and also applying all bean post processors.
This is effectively a superset of what initializeBean
provides, fully applying the configuration specified by the corresponding
bean definition.
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 with the given name
BeansException
- if the initialization failedinitializeBean(java.lang.Object, java.lang.String)
Object initializeBean(Object existingBean, String beanName) throws BeansException
setBeanName
and setBeanFactory
,
also applying all bean post processors.
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
)
BeansException
- if the initialization failedObject applyBeanPostProcessorsBeforeInitialization(Object existingBean, 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 instancebeanName
- the name of the bean
BeansException
- if any post-processing failedBeanPostProcessor.postProcessBeforeInitialization(java.lang.Object, java.lang.String)
Object applyBeanPostProcessorsAfterInitialization(Object existingBean, 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 instancebeanName
- the name of the bean
BeansException
- if any post-processing failedBeanPostProcessor.postProcessAfterInitialization(java.lang.Object, java.lang.String)
|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |