Package org.springframework.beans.factory.config

# Interface AutowireCapableBeanFactory

All Superinterfaces:
  `BeanFactory`

All Known Subinterfaces:
  `ConfigurableListableBeanFactory`

All Known Implementing Classes:
  `AbstractAutowireCapableBeanFactory`, `DefaultListableBeanFactory`

public interface AutowireCapableBeanFactory extends BeanFactory
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 `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 `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.

Since:
  04.12.2003
Author:
  Juergen Hoeller
See Also:
  - `BeanFactoryAware`
  - `ConfigurableListableBeanFactory`
  - `org.springframework.context.ApplicationContext#getAutowireCapableBeanFactory()`

## Field Summary

Fields
Modifier and Type
Field
Description
`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.
`static final int`
`AUTOWIRE_BY_NAME`
Constant that indicates autowiring bean properties by name (applying to all bean property setters).
`static final int`
`AUTOWIRE_BY_TYPE`
Constant that indicates autowiring bean properties by type (applying to all bean property setters).
`static final int`
`AUTOWIRE_CONSTRUCTOR`
Constant that indicates autowiring the greediest constructor that can be satisfied (involves resolving the appropriate constructor).
`static final int`
`AUTOWIRE_NO`
Constant that indicates no externally defined autowiring.
`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, for example, "com.mypackage.MyClass.ORIGINAL", in order to enforce the given instance to be returned, i.e.

### Fields inherited from interface org.springframework.beans.factory.BeanFactory

`FACTORY_BEAN_PREFIX, FACTORY_BEAN_PREFIX_CHAR`

## Method Summary

Modifier and Type
Method
Description
`Object`
`applyBeanPostProcessorsAfterInitialization(Object existingBean, String beanName)`
Deprecated.
as of 6.1, in favor of implicit post-processing through `initializeBean(Object, String)`
`Object`
`applyBeanPostProcessorsBeforeInitialization(Object existingBean, String beanName)`
Deprecated.
as of 6.1, in favor of implicit post-processing through `initializeBean(Object, String)`
`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`
`autowireBean(Object existingBean)`
Populate the given bean instance through applying after-instantiation callbacks and bean property post-processing (for example, for annotation-driven injection).
`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 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).
`Object`
`createBean(Class<?> beanClass, int autowireMode, boolean dependencyCheck)`
Deprecated.
as of 6.1, in favor of `createBean(Class)`
`<T> T`
`createBean(Class<T> beanClass)`
Fully create a new bean instance of the given class.
`void`
`destroyBean(Object existingBean)`
Destroy the given bean instance (typically coming from `createBean(Class)`), applying the `DisposableBean` contract as well as registered `DestructionAwareBeanPostProcessors`.
`Object`
`initializeBean(Object existingBean, 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).
`Object`
`resolveBeanByName(String name, DependencyDescriptor descriptor)`
Resolve a bean instance for the given bean name, providing a dependency descriptor for exposure to target factory methods.
`Object`
`resolveDependency(DependencyDescriptor descriptor, String requestingBeanName)`
Resolve the specified dependency against the beans defined in this factory.
`Object`
`resolveDependency(DependencyDescriptor descriptor, String requestingBeanName, Set<String> autowiredBeanNames, TypeConverter typeConverter)`
Resolve the specified dependency against the beans defined in this factory.
`<T> NamedBeanHolder<T>`
`resolveNamedBean(Class<T> requiredType)`
Resolve the bean instance that uniquely matches the given object type, if any, including its bean name.

### Methods inherited from interface org.springframework.beans.factory.BeanFactory

`containsBean, getAliases, getBean, getBean, getBean, getBean, getBean, getBeanProvider, getBeanProvider, getType, getType, isPrototype, isSingleton, isTypeMatch, isTypeMatch`

## Field Details

### AUTOWIRE_NO

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(java.lang.Class<?>, int, boolean)`
  - `autowireBeanProperties(java.lang.Object, int, boolean)`
  - Constant Field Values

### AUTOWIRE_BY_NAME

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

See Also:
  - `autowire(java.lang.Class<?>, int, boolean)`
  - `autowireBeanProperties(java.lang.Object, int, boolean)`
  - Constant Field Values

### AUTOWIRE_BY_TYPE

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

See Also:
  - `autowire(java.lang.Class<?>, int, boolean)`
  - `autowireBeanProperties(java.lang.Object, int, boolean)`
  - Constant Field Values

### AUTOWIRE_CONSTRUCTOR

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

See Also:
  - `autowire(java.lang.Class<?>, int, boolean)`
  - Constant Field Values

### AUTOWIRE_AUTODETECT

@Deprecated 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.

See Also:
  - `autowire(java.lang.Class<?>, int, boolean)`
  - Constant Field Values

### ORIGINAL_INSTANCE_SUFFIX

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, for example, "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)`
  - Constant Field Values

## Method Details

### createBean

<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(java.lang.Class<?>, java.lang.String)` (for example, for annotation-driven constructor selection).

Parameters:
  `beanClass` - the class of the bean to create
Returns:
  the new bean instance
Throws:
  `BeansException` - if instantiation or wiring failed

### autowireBean

void autowireBean(Object existingBean) throws BeansException
Populate the given bean instance through applying after-instantiation callbacks and bean property post-processing (for example, 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(java.lang.Object, int, boolean)` for those purposes.

Parameters:
  `existingBean` - the existing bean instance
Throws:
  `BeansException` - if wiring failed

### configureBean

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(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!

Parameters:
  `existingBean` - the existing bean instance
  `beanName` - the name of the bean, to be passed to it if necessary (a bean definition of that name has to be available)
Returns:
  the bean instance to use, either the original or a wrapped one
Throws:
  `NoSuchBeanDefinitionException` - if there is no bean definition with the given name
  `BeansException` - if the initialization failed
See Also:
  - `initializeBean(java.lang.Object, java.lang.String)`

### createBean

@Deprecated(since="6.1") Object createBean(Class<?> beanClass, int autowireMode, boolean dependencyCheck) throws BeansException
Deprecated.
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(java.lang.Class<?>, int, boolean)` provides, adding `initializeBean(java.lang.Object, java.lang.String)` behavior.

Parameters:
  `beanClass` - the class of the bean to create
  `autowireMode` - by name or type, using the constants in this interface
  `dependencyCheck` - whether to perform a dependency check for objects (not applicable to autowiring a constructor, thus ignored there)
Returns:
  the new bean instance
Throws:
  `BeansException` - if instantiation or wiring failed
See Also:
  - `AUTOWIRE_NO`
  - `AUTOWIRE_BY_NAME`
  - `AUTOWIRE_BY_TYPE`
  - `AUTOWIRE_CONSTRUCTOR`

### autowire

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 (for example, 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.

Parameters:
  `beanClass` - the class of the bean to instantiate
  `autowireMode` - by name or type, using the constants in this interface
  `dependencyCheck` - whether to perform a dependency check for object references in the bean instance (not applicable to autowiring a constructor, thus ignored there)
Returns:
  the new bean instance
Throws:
  `BeansException` - if instantiation or wiring failed
See Also:
  - `AUTOWIRE_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)`

### autowireBeanProperties

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 (for example, 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.

Parameters:
  `existingBean` - the existing bean instance
  `autowireMode` - by name or type, using the constants in this interface
  `dependencyCheck` - whether to perform a dependency check for object references in the bean instance
Throws:
  `BeansException` - if wiring failed
See Also:
  - `AUTOWIRE_BY_NAME`
  - `AUTOWIRE_BY_TYPE`
  - `AUTOWIRE_NO`

### applyBeanPropertyValues

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(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.

Parameters:
  `existingBean` - the existing bean instance
  `beanName` - the name of the bean definition in the bean factory (a bean definition of that name has to be available)
Throws:
  `NoSuchBeanDefinitionException` - if there is no bean definition with the given name
  `BeansException` - if applying the property values failed
See Also:
  - `autowireBeanProperties(java.lang.Object, int, boolean)`

### initializeBean

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` - the existing bean instance
  `beanName` - 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:
  the bean instance to use, either the original or a wrapped one
Throws:
  `BeansException` - if the initialization failed
See Also:
  - `ORIGINAL_INSTANCE_SUFFIX`

### applyBeanPostProcessorsBeforeInitialization

@Deprecated(since="6.1") Object applyBeanPostProcessorsBeforeInitialization(Object existingBean, String beanName) throws BeansException
Deprecated.
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` - the existing bean instance
  `beanName` - 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:
  the bean instance to use, either the original or a wrapped one
Throws:
  `BeansException` - if any post-processing failed
See Also:
  - `BeanPostProcessor.postProcessBeforeInitialization(java.lang.Object, java.lang.String)`
  - `ORIGINAL_INSTANCE_SUFFIX`

### applyBeanPostProcessorsAfterInitialization

@Deprecated(since="6.1") Object applyBeanPostProcessorsAfterInitialization(Object existingBean, String beanName) throws BeansException
Deprecated.
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` - the existing bean instance
  `beanName` - 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:
  the bean instance to use, either the original or a wrapped one
Throws:
  `BeansException` - if any post-processing failed
See Also:
  - `BeanPostProcessor.postProcessAfterInitialization(java.lang.Object, java.lang.String)`
  - `ORIGINAL_INSTANCE_SUFFIX`

### destroyBean

void destroyBean(Object existingBean)
Destroy the given bean instance (typically coming from `createBean(Class)`), 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.

Parameters:
  `existingBean` - the bean instance to destroy

### resolveNamedBean

<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 `BeanFactory.getBean(Class)` which preserves the bean name of the matching instance.

Parameters:
  `requiredType` - type the bean must match; can be an interface or superclass
Returns:
  the bean name plus bean instance
Throws:
  `NoSuchBeanDefinitionException` - if no matching bean was found
  `NoUniqueBeanDefinitionException` - if more than one matching bean was found
  `BeansException` - if the bean could not be created
Since:
  4.3.3
See Also:
  - `BeanFactory.getBean(Class)`

### resolveBeanByName

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 `BeanFactory.getBean(String, Class)` which supports factory methods with an `InjectionPoint` argument.

Parameters:
  `name` - the name of the bean to look up
  `descriptor` - the dependency descriptor for the requesting injection point
Returns:
  the corresponding bean instance
Throws:
  `NoSuchBeanDefinitionException` - if there is no bean with the specified name
  `BeansException` - if the bean could not be created
Since:
  5.1.5
See Also:
  - `BeanFactory.getBean(String, Class)`

### resolveDependency

@Nullable Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName) throws BeansException
Resolve the specified dependency against the beans defined in this factory.

Parameters:
  `descriptor` - the descriptor for the dependency (field/method/constructor)
  `requestingBeanName` - the name of the bean which declares the given dependency
Returns:
  the resolved object, or `null` if none found
Throws:
  `NoSuchBeanDefinitionException` - if no matching bean was found
  `NoUniqueBeanDefinitionException` - if more than one matching bean was found
  `BeansException` - if dependency resolution failed for any other reason
Since:
  2.5
See Also:
  - `resolveDependency(DependencyDescriptor, String, Set, TypeConverter)`

### resolveDependency

@Nullable Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName, @Nullable Set<String> autowiredBeanNames, @Nullable TypeConverter typeConverter) throws BeansException
Resolve the specified dependency against the beans defined in this factory.

Parameters:
  `descriptor` - the descriptor for the dependency (field/method/constructor)
  `requestingBeanName` - the name of the bean which declares the given dependency
  `autowiredBeanNames` - a Set that all names of autowired beans (used for resolving the given dependency) are supposed to be added to
  `typeConverter` - the TypeConverter to use for populating arrays and collections
Returns:
  the resolved object, or `null` if none found
Throws:
  `NoSuchBeanDefinitionException` - if no matching bean was found
  `NoUniqueBeanDefinitionException` - if more than one matching bean was found
  `BeansException` - if dependency resolution failed for any other reason
Since:
  2.5
See Also:
  - `DependencyDescriptor`