public interface

AutowireCapableBeanFactory

implements BeanFactory
org.springframework.beans.factory.config.AutowireCapableBeanFactory
Known Indirect Subclasses

Class Overview

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

Summary

Constants
int AUTOWIRE_AUTODETECT This constant is deprecated. as of Spring 3.0: If you are using mixed autowiring strategies, prefer annotation-based autowiring for clearer demarcation of autowiring needs.
int AUTOWIRE_BY_NAME Constant that indicates autowiring bean properties by name (applying to all bean property setters).
int AUTOWIRE_BY_TYPE Constant that indicates autowiring bean properties by type (applying to all bean property setters).
int AUTOWIRE_CONSTRUCTOR Constant that indicates autowiring the greediest constructor that can be satisfied (involves resolving the appropriate constructor).
int AUTOWIRE_NO Constant that indicates no externally defined autowiring.
[Expand]
Inherited Constants
From interface org.springframework.beans.factory.BeanFactory
Public Methods
abstract Object applyBeanPostProcessorsAfterInitialization(Object existingBean, String beanName)
Apply BeanPostProcessors to the given existing bean instance, invoking their postProcessAfterInitialization methods.
abstract Object applyBeanPostProcessorsBeforeInitialization(Object existingBean, String beanName)
Apply BeanPostProcessors to the given existing bean instance, invoking their postProcessBeforeInitialization methods.
abstract void applyBeanPropertyValues(Object existingBean, String beanName)
Apply the property values of the bean definition with the given name to the given bean instance.
abstract Object autowire(Class beanClass, int autowireMode, boolean dependencyCheck)
Instantiate a new bean instance of the given class with the specified autowire strategy.
abstract void autowireBean(Object existingBean)
Populate the given bean instance through applying after-instantiation callbacks and bean property post-processing (e.g.
abstract void autowireBeanProperties(Object existingBean, int autowireMode, boolean dependencyCheck)
Autowire the bean properties of the given bean instance by name or type.
abstract 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).
abstract Object createBean(Class beanClass, int autowireMode, boolean dependencyCheck)
Fully create a new bean instance of the given class with the specified autowire strategy.
abstract <T> T createBean(Class<T> beanClass)
Fully create a new bean instance of the given class.
abstract 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).
abstract Object resolveDependency(DependencyDescriptor descriptor, String beanName)
Resolve the specified dependency against the beans defined in this factory.
abstract Object resolveDependency(DependencyDescriptor descriptor, String beanName, Set<String> autowiredBeanNames, TypeConverter typeConverter)
Resolve the specified dependency against the beans defined in this factory.
[Expand]
Inherited Methods
From interface org.springframework.beans.factory.BeanFactory

Constants

public static final int AUTOWIRE_AUTODETECT

Also: SpringBeans

This constant is 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.

Constant Value: 4 (0x00000004)

public static final int AUTOWIRE_BY_NAME

Also: SpringBeans

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

Constant Value: 1 (0x00000001)

public static final int AUTOWIRE_BY_TYPE

Also: SpringBeans

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

Constant Value: 2 (0x00000002)

public static final int AUTOWIRE_CONSTRUCTOR

Also: SpringBeans

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

Constant Value: 3 (0x00000003)

public static final int AUTOWIRE_NO

Also: SpringBeans

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

Constant Value: 0 (0x00000000)

Public Methods

public abstract Object applyBeanPostProcessorsAfterInitialization (Object existingBean, String beanName)

Also: SpringBeans

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 new bean instance
beanName the name of the bean
Returns
  • the bean instance to use, either the original or a wrapped one
Throws
BeansException if any post-processing failed

public abstract Object applyBeanPostProcessorsBeforeInitialization (Object existingBean, String beanName)

Also: SpringBeans

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 new bean instance
beanName the name of the bean
Returns
  • the bean instance to use, either the original or a wrapped one
Throws
BeansException if any post-processing failed

public abstract void applyBeanPropertyValues (Object existingBean, String beanName)

Also: SpringBeans

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(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(Object, 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

public abstract Object autowire (Class beanClass, int autowireMode, boolean dependencyCheck)

Also: SpringBeans

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(Object, 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

public abstract void autowireBean (Object existingBean)

Also: SpringBeans

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(Object, int, boolean) for that purposes.

Parameters
existingBean the existing bean instance
Throws
BeansException if wiring failed

public abstract void autowireBeanProperties (Object existingBean, int autowireMode, boolean dependencyCheck)

Also: SpringBeans

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(Object, 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

public abstract Object configureBean (Object existingBean, String beanName)

Also: SpringBeans

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(Object, 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

public abstract Object createBean (Class beanClass, int autowireMode, boolean dependencyCheck)

Also: SpringBeans

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(Class, int, boolean) provides, adding initializeBean(Object, 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

public abstract T createBean (Class<T> beanClass)

Also: SpringBeans

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 initialiation callbacks. It does not imply traditional by-name or by-type autowiring of properties; use createBean(Class, int, boolean) for that purposes.

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

public abstract Object initializeBean (Object existingBean, String beanName)

Also: SpringBeans

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)
Returns
  • the bean instance to use, either the original or a wrapped one
Throws
BeansException if the initialization failed

public abstract Object resolveDependency (DependencyDescriptor descriptor, String beanName)

Also: SpringBeans

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

Parameters
descriptor the descriptor for the dependency
beanName the name of the bean which declares the present dependency
Returns
  • the resolved object, or null if none found
Throws
BeansException in dependency resolution failed

public abstract Object resolveDependency (DependencyDescriptor descriptor, String beanName, Set<String> autowiredBeanNames, TypeConverter typeConverter)

Also: SpringBeans

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

Parameters
descriptor the descriptor for the dependency
beanName the name of the bean which declares the present dependency
autowiredBeanNames a Set that all names of autowired beans (used for resolving the present 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
BeansException in dependency resolution failed