Top Description Fields Methods
org.springframework.beans.factory.config

public Interface AutowireCapableBeanFactory

extends BeanFactory
Known Direct Subinterfaces
org.springframework.beans.factory.config.ConfigurableListableBeanFactory
Known Direct Implementers
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
Imports
java.util.Set, org.springframework.beans.BeansException, .TypeConverter, org.springframework.beans.factory.BeanFactory, .NoSuchBeanDefinitionException, .NoUniqueBeanDefinitionException, org.springframework.lang.Nullable

Extension of the org.springframework.beans.factory.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 org.springframework.beans.factory.BeanFactory or org.springframework.beans.factory.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 org.springframework.context.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 org.springframework.context.ApplicationContext#getAutowireCapableBeanFactory() method.

You may also implement the org.springframework.beans.factory.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.

Author
Juergen Hoeller
Since
04.12.2003
See Also
org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.config.ConfigurableListableBeanFactory, org.springframework.context.ApplicationContext#getAutowireCapableBeanFactory()

Field Summary

Modifier and TypeField and Description
public static final 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.
Constant that indicates determining an appropriate autowire strategy through introspection of the bean class.
public static final int
AUTOWIRE_BY_NAME

Constant that indicates autowiring bean properties by name (applying to all bean property setters).

public static final int
AUTOWIRE_BY_TYPE

Constant that indicates autowiring bean properties by type (applying to all bean property setters).

public static final int
AUTOWIRE_CONSTRUCTOR

Constant that indicates autowiring the greediest constructor that can be satisfied (involves resolving the appropriate constructor).

public static final int
AUTOWIRE_NO

Constant that indicates no externally defined autowiring.

public static final 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. "com.mypackage.MyClass.ORIGINAL", in order to enforce the given instance to be returned, i.e. no proxies etc.

Inherited from org.springframework.beans.factory.BeanFactory:
FACTORY_BEAN_PREFIX

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

the bean instance to use, either the original or a wrapped one
applyBeanPostProcessorsAfterInitialization
(Object
the existing bean instance
existingBean
,
String
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)
beanName
)
Deprecated since 6.1. as of 6.1, in favor of implicit post-processing through initializeBean(Object, String)

Apply BeanPostProcessors to the given existing bean instance, invoking their postProcessAfterInitialization methods.

public Object

Returns:

the bean instance to use, either the original or a wrapped one
applyBeanPostProcessorsBeforeInitialization
(Object
the existing bean instance
existingBean
,
String
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)
beanName
)
Deprecated since 6.1. as of 6.1, in favor of implicit post-processing through initializeBean(Object, String)

Apply BeanPostProcessors to the given existing bean instance, invoking their postProcessBeforeInitialization methods.

public void
applyBeanPropertyValues(Object
the existing bean instance
existingBean
,
String
the name of the bean definition in the bean factory (a bean definition of that name has to be available)
beanName
)

Apply the property values of the bean definition with the given name to the given bean instance.

public Object

Returns:

the new bean instance
autowire
(Class<?>
the class of the bean to instantiate
beanClass
,
int
by name or type, using the constants in this interface
autowireMode
,
boolean
whether to perform a dependency check for object references in the bean instance (not applicable to autowiring a constructor, thus ignored there)
dependencyCheck
)

Instantiate a new bean instance of the given class with the specified autowire strategy.

public void
autowireBean(Object
the existing bean instance
existingBean
)

Populate the given bean instance through applying after-instantiation callbacks and bean property post-processing (e.g. for annotation-driven injection).

public void
autowireBeanProperties(Object
the existing bean instance
existingBean
,
int
by name or type, using the constants in this interface
autowireMode
,
boolean
whether to perform a dependency check for object references in the bean instance
dependencyCheck
)

Autowire the bean properties of the given bean instance by name or type.

public Object

Returns:

the bean instance to use, either the original or a wrapped one
configureBean
(Object
the existing bean instance
existingBean
,
String
the name of the bean, to be passed to it if necessary (a bean definition of that name has to be available)
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).

public <T> T

Returns:

the new bean instance
createBean
(Class<T>
the class of the bean to create
beanClass
)

Fully create a new bean instance of the given class.

public Object

Returns:

the new bean instance
createBean
(Class<?>
the class of the bean to create
beanClass
,
int
by name or type, using the constants in this interface
autowireMode
,
boolean
whether to perform a dependency check for objects (not applicable to autowiring a constructor, thus ignored there)
dependencyCheck
)
Deprecated since 6.1. as of 6.1, in favor of createBean(Class)

Fully create a new bean instance of the given class with the specified autowire strategy.

public void
destroyBean(Object
the bean instance to destroy
existingBean
)

Destroy the given bean instance (typically coming from createBean(Class)), applying the org.springframework.beans.factory.DisposableBean contract as well as registered DestructionAwareBeanPostProcessors.

public Object

Returns:

the bean instance to use, either the original or a wrapped one
initializeBean
(Object
the existing bean instance
existingBean
,
String
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)
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).

public Object

Returns:

the corresponding bean instance
resolveBeanByName
(String
the name of the bean to look up
name
,
DependencyDescriptor
the dependency descriptor for the requesting injection point
descriptor
)

Resolve a bean instance for the given bean name, providing a dependency descriptor for exposure to target factory methods.

public Object

Returns:

the resolved object, or null if none found
resolveDependency
(DependencyDescriptor
the descriptor for the dependency (field/method/constructor)
descriptor
,
String
the name of the bean which declares the given dependency
requestingBeanName
)

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

public Object

Returns:

the resolved object, or null if none found
resolveDependency
(DependencyDescriptor
the descriptor for the dependency (field/method/constructor)
descriptor
,
String
the name of the bean which declares the given dependency
requestingBeanName
,
Set<String>
a Set that all names of autowired beans (used for resolving the given dependency) are supposed to be added to
autowiredBeanNames
,
TypeConverter
the TypeConverter to use for populating arrays and collections
typeConverter
)

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

public <T> NamedBeanHolder<T>

Returns:

the bean name plus bean instance
resolveNamedBean
(Class<T>
type the bean must match; can be an interface or superclass
requiredType
)

Resolve the bean instance that uniquely matches the given object type, if any, including its bean name.

Inherited from org.springframework.beans.factory.BeanFactory:
containsBeangetAliasesgetBeangetBeangetBeangetBeangetBeangetBeanProvidergetBeanProvidergetTypegetTypeisPrototypeisSingletonisTypeMatchisTypeMatch

Field Detail

AUTOWIRE_AUTODETECTback to summary
public static final 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.

Constant that indicates determining an appropriate autowire strategy through introspection of the bean class.

Annotations
@Deprecated
See Also
autowire
AUTOWIRE_BY_NAMEback to summary
public static final int AUTOWIRE_BY_NAME

Constant that indicates autowiring bean properties by name (applying to all bean property setters).

See Also
autowire, autowireBeanProperties
AUTOWIRE_BY_TYPEback to summary
public static final int AUTOWIRE_BY_TYPE

Constant that indicates autowiring bean properties by type (applying to all bean property setters).

See Also
autowire, autowireBeanProperties
AUTOWIRE_CONSTRUCTORback to summary
public static final int AUTOWIRE_CONSTRUCTOR

Constant that indicates autowiring the greediest constructor that can be satisfied (involves resolving the appropriate constructor).

See Also
autowire
AUTOWIRE_NOback to summary
public static final int AUTOWIRE_NO

Constant that indicates no externally defined autowiring. Note that BeanFactoryAware etc and annotation-driven injection will still be applied.

See Also
autowire, autowireBeanProperties
ORIGINAL_INSTANCE_SUFFIXback to summary
public static final 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. "com.mypackage.MyClass.ORIGINAL", in order to enforce the given instance to be returned, i.e. no proxies etc.

Since
5.1
See Also
initializeBean(Object, String), applyBeanPostProcessorsBeforeInitialization(Object, String), applyBeanPostProcessorsAfterInitialization(Object, String)

Method Detail

applyBeanPostProcessorsAfterInitializationback to summary
public Object applyBeanPostProcessorsAfterInitialization(Object existingBean, String beanName) throws BeansException

Deprecated

since 6.1.

as of 6.1, in favor of implicit post-processing through initializeBean(Object, String)

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:Object

the existing bean instance

beanName:String

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)

Returns:Object

the bean instance to use, either the original or a wrapped one

Annotations
@Deprecated
since:6.1
Exceptions
BeansException:
if any post-processing failed
See Also
BeanPostProcessor#postProcessAfterInitialization, ORIGINAL_INSTANCE_SUFFIX
applyBeanPostProcessorsBeforeInitializationback to summary
public Object applyBeanPostProcessorsBeforeInitialization(Object existingBean, String beanName) throws BeansException

Deprecated

since 6.1.

as of 6.1, in favor of implicit post-processing through initializeBean(Object, String)

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:Object

the existing bean instance

beanName:String

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)

Returns:Object

the bean instance to use, either the original or a wrapped one

Annotations
@Deprecated
since:6.1
Exceptions
BeansException:
if any post-processing failed
See Also
BeanPostProcessor#postProcessBeforeInitialization, ORIGINAL_INSTANCE_SUFFIX
applyBeanPropertyValuesback to summary
public void applyBeanPropertyValues(Object existingBean, String beanName) throws BeansException

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 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. However, InstantiationAwareBeanPostProcessor callbacks are applied, if applicable to the configuration of the instance.

Parameters
existingBean:Object

the existing bean instance

beanName:String

the name of the bean definition in the bean factory (a bean definition of that name has to be available)

Exceptions
BeansException:
if applying the property values failed
NoSuchBeanDefinitionException:
if there is no bean definition with the given name
See Also
autowireBeanProperties
autowireback to summary
public Object autowire(Class<?> beanClass, int autowireMode, boolean dependencyCheck) throws BeansException

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. However, InstantiationAwareBeanPostProcessor callbacks are applied, if applicable to the construction of the instance.

Parameters
beanClass:Class<?>

the class of the bean to instantiate

autowireMode:int

by name or type, using the constants in this interface

dependencyCheck:boolean

whether to perform a dependency check for object references in the bean instance (not applicable to autowiring a constructor, thus ignored there)

Returns:Object

the new bean instance

Exceptions
BeansException:
if instantiation or wiring failed
See Also
AUTOWIRE_NO, AUTOWIRE_BY_NAME, AUTOWIRE_BY_TYPE, AUTOWIRE_CONSTRUCTOR, AUTOWIRE_AUTODETECT, initializeBean, applyBeanPostProcessorsBeforeInitialization, applyBeanPostProcessorsAfterInitialization
autowireBeanback to summary
public void autowireBean(Object existingBean) throws BeansException

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 for those purposes.

Parameters
existingBean:Object

the existing bean instance

Exceptions
BeansException:
if wiring failed
autowireBeanPropertiesback to summary
public void autowireBeanProperties(Object existingBean, int autowireMode, boolean dependencyCheck) throws BeansException

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. However, InstantiationAwareBeanPostProcessor callbacks are applied, if applicable to the configuration of the instance.

Parameters
existingBean:Object

the existing bean instance

autowireMode:int

by name or type, using the constants in this interface

dependencyCheck:boolean

whether to perform a dependency check for object references in the bean instance

Exceptions
BeansException:
if wiring failed
See Also
AUTOWIRE_BY_NAME, AUTOWIRE_BY_TYPE, AUTOWIRE_NO
configureBeanback to summary
public Object configureBean(Object existingBean, String beanName) throws BeansException

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 provides, fully applying the configuration specified by the corresponding bean definition.

Note

This method requires a bean definition for the given name!

Parameters
existingBean:Object

the existing bean instance

beanName:String

the name of the bean, to be passed to it if necessary (a bean definition of that name has to be available)

Returns:Object

the bean instance to use, either the original or a wrapped one

Exceptions
BeansException:
if the initialization failed
NoSuchBeanDefinitionException:
if there is no bean definition with the given name
See Also
initializeBean
createBeanback to summary
public <T> T createBean(Class<T> beanClass) throws BeansException

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 initialization callbacks. Constructor resolution is based on Kotlin primary / single public / single non-public, with a fallback to the default constructor in ambiguous scenarios, also influenced by SmartInstantiationAwareBeanPostProcessor#determineCandidateConstructors (e.g. for annotation-driven constructor selection).

Parameters
beanClass:Class<T>

the class of the bean to create

Returns:T

the new bean instance

Exceptions
BeansException:
if instantiation or wiring failed
createBeanback to summary
public Object createBean(Class<?> beanClass, int autowireMode, boolean dependencyCheck) throws BeansException

Deprecated

since 6.1.

as of 6.1, in favor of createBean(Class)

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 provides, adding initializeBean behavior.

Parameters
beanClass:Class<?>

the class of the bean to create

autowireMode:int

by name or type, using the constants in this interface

dependencyCheck:boolean

whether to perform a dependency check for objects (not applicable to autowiring a constructor, thus ignored there)

Returns:Object

the new bean instance

Annotations
@Deprecated
since:6.1
Exceptions
BeansException:
if instantiation or wiring failed
See Also
AUTOWIRE_NO, AUTOWIRE_BY_NAME, AUTOWIRE_BY_TYPE, AUTOWIRE_CONSTRUCTOR
destroyBeanback to summary
public void destroyBean(Object existingBean)

Destroy the given bean instance (typically coming from createBean(Class)), applying the org.springframework.beans.factory.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.

Parameters
existingBean:Object

the bean instance to destroy

initializeBeanback to summary
public Object initializeBean(Object existingBean, String beanName) throws BeansException

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:Object

the existing bean instance

beanName:String

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)

Returns:Object

the bean instance to use, either the original or a wrapped one

Exceptions
BeansException:
if the initialization failed
See Also
ORIGINAL_INSTANCE_SUFFIX
resolveBeanByNameback to summary
public Object resolveBeanByName(String name, DependencyDescriptor descriptor) throws BeansException

Resolve a bean instance for the given bean name, providing a dependency descriptor for exposure to target factory methods.

This is effectively a variant of getBean(String, Class) which supports factory methods with an org.springframework.beans.factory.InjectionPoint argument.

Parameters
name:String

the name of the bean to look up

descriptor:DependencyDescriptor

the dependency descriptor for the requesting injection point

Returns:Object

the corresponding bean instance

Exceptions
BeansException:
if the bean could not be created
NoSuchBeanDefinitionException:
if there is no bean with the specified name
Since
5.1.5
See Also
getBean(String, Class)
resolveDependencyback to summary
public Object resolveDependency(DependencyDescriptor descriptor, String requestingBeanName) throws BeansException

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

Parameters
descriptor:DependencyDescriptor

the descriptor for the dependency (field/method/constructor)

requestingBeanName:String

the name of the bean which declares the given dependency

Returns:Object

the resolved object, or null if none found

Annotations
@Nullable
Exceptions
BeansException:
if dependency resolution failed for any other reason
NoSuchBeanDefinitionException:
if no matching bean was found
NoUniqueBeanDefinitionException:
if more than one matching bean was found
Since
2.5
See Also
resolveDependency(DependencyDescriptor, String, Set, TypeConverter)
resolveDependencyback to summary
public Object resolveDependency(DependencyDescriptor descriptor, String requestingBeanName, Set<String> autowiredBeanNames, TypeConverter typeConverter) throws BeansException

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

Parameters
descriptor:DependencyDescriptor

the descriptor for the dependency (field/method/constructor)

requestingBeanName:String

the name of the bean which declares the given dependency

autowiredBeanNames:Set<String>

a Set that all names of autowired beans (used for resolving the given dependency) are supposed to be added to

typeConverter:TypeConverter

the TypeConverter to use for populating arrays and collections

Returns:Object

the resolved object, or null if none found

Annotations
@Nullable
Exceptions
BeansException:
if dependency resolution failed for any other reason
NoSuchBeanDefinitionException:
if no matching bean was found
NoUniqueBeanDefinitionException:
if more than one matching bean was found
Since
2.5
See Also
DependencyDescriptor
resolveNamedBeanback to summary
public <T> NamedBeanHolder<T> resolveNamedBean(Class<T> requiredType) throws BeansException

Resolve the bean instance that uniquely matches the given object type, if any, including its bean name.

This is effectively a variant of getBean(Class) which preserves the bean name of the matching instance.

Parameters
requiredType:Class<T>

type the bean must match; can be an interface or superclass

Returns:NamedBeanHolder<T>

the bean name plus bean instance

Exceptions
BeansException:
if the bean could not be created
NoSuchBeanDefinitionException:
if no matching bean was found
NoUniqueBeanDefinitionException:
if more than one matching bean was found
Since
4.3.3
See Also
getBean(Class)