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.
or org. 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. 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.
method.
You may also implement the org.
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.
org.springframework.beans.factory.BeanFactoryAware , org.springframework.beans.factory.config.ConfigurableListableBeanFactory , org.springframework.context.ApplicationContext#getAutowireCapableBeanFactory()
| Modifier and Type | Field 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. |
| Modifier and Type | Method and Description |
|---|---|
| public Object | Returns: the bean instance to use, either the original or a wrapped onethe existing bean instance existingBean, String the name of the bean, to be passed to it if necessary
(only passed to beanName)BeanPostProcessors;
can follow the ORIGINAL_INSTANCE_SUFFIX convention in order to
enforce the given instance to be returned, i.e. no proxies etc)
Deprecated
since 6.1. as of 6.1, in favor of implicit post-processing through
initializeBean(Object, String)
Apply |
| public Object | Returns: the bean instance to use, either the original or a wrapped onethe existing bean instance existingBean, String the name of the bean, to be passed to it if necessary
(only passed to beanName)BeanPostProcessors;
can follow the ORIGINAL_INSTANCE_SUFFIX convention in order to
enforce the given instance to be returned, i.e. no proxies etc)
Deprecated
since 6.1. as of 6.1, in favor of implicit post-processing through
initializeBean(Object, String)
Apply |
| 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 instancethe 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 onethe 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 |
| public <T> T | Returns: the new bean instancethe class of the bean to create beanClass)Fully create a new bean instance of the given class. |
| public Object | Returns: the new bean instancethe 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 |
| public Object | Returns: the bean instance to use, either the original or a wrapped onethe existing bean instance existingBean, String the name of the bean, to be passed to it if necessary
(only passed to beanName)BeanPostProcessors;
can follow the ORIGINAL_INSTANCE_SUFFIX convention in order to
enforce the given instance to be returned, i.e. no proxies etc)Initialize the given raw bean, applying factory callbacks
such as |
| public Object | Returns: the corresponding bean instancethe 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, ornull if none foundthe 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, ornull if none foundthe 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 | Returns: the bean name plus bean instancetype 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. |
| AUTOWIRE_AUTODETECT | back 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.
| |
| AUTOWIRE_BY_NAME | back to summary |
|---|---|
| public static final int AUTOWIRE_BY_NAME Constant that indicates autowiring bean properties by name (applying to all bean property setters).
| |
| AUTOWIRE_BY_TYPE | back to summary |
|---|---|
| public static final int AUTOWIRE_BY_TYPE Constant that indicates autowiring bean properties by type (applying to all bean property setters).
| |
| AUTOWIRE_CONSTRUCTOR | back to summary |
|---|---|
| public static final int AUTOWIRE_CONSTRUCTOR Constant that indicates autowiring the greediest constructor that can be satisfied (involves resolving the appropriate constructor).
| |
| AUTOWIRE_NO | back 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.
| |
| ORIGINAL_INSTANCE_SUFFIX | back 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. | |
| applyBeanPostProcessorsAfterInitialization | back 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
Apply
| |
| applyBeanPostProcessorsBeforeInitialization | back 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
Apply
| |
| applyBeanPropertyValues | back 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 Note This method requires a bean definition for the given name! Does not apply standard
| |
| autowire | back 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 Does not apply standard
| |
| autowireBean | back 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 | back 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 Does not apply standard
| |
| configureBean | back 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 This is effectively a superset of what Note This method requires a bean definition for the given name!
| |
| createBean | back 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
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
| |
| createBean | back to summary |
|---|---|
| public Object createBean(Class<?> beanClass, int autowireMode, boolean dependencyCheck) throws BeansException
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
| |
| destroyBean | back to summary |
|---|---|
| public void destroyBean(Object existingBean) Destroy the given bean instance (typically coming from Any exception that arises during destruction should be caught and logged instead of propagated to the caller of this method.
| |
| initializeBean | back to summary |
|---|---|
| public Object initializeBean(Object existingBean, String beanName) throws BeansException Initialize the given raw bean, applying factory callbacks
such as 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.
| |
| resolveBeanByName | back 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
| |
| resolveDependency | back to summary |
|---|---|
| public Object resolveDependency(DependencyDescriptor descriptor, String requestingBeanName) throws BeansException Resolve the specified dependency against the beans defined in this factory.
| |
| resolveDependency | back 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.
| |
| resolveNamedBean | back to summary |
|---|---|
| public <T> NamedBeanHolder Resolve the bean instance that uniquely matches the given object type, if any, including its bean name. This is effectively a variant of
| |