站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Spring Framework 2.0.5 API 文档英文版

InstantiationAwareBeanPostProcessor (Spring Framework API 2.0) - Spring Framework 2.0.5 API 文档英文版

The Spring Framework

org.springframework.beans.factory.config
Interface InstantiationAwareBeanPostProcessor

All Superinterfaces:
BeanPostProcessor
All Known Subinterfaces:
SmartInstantiationAwareBeanPostProcessor
All Known Implementing Classes:
AbstractAdvisorAutoProxyCreator, AbstractAutoProxyCreator, AnnotationAwareAspectJAutoProxyCreator, AspectJAwareAdvisorAutoProxyCreator, BeanNameAutoProxyCreator, DefaultAdvisorAutoProxyCreator, InstantiationAwareBeanPostProcessorAdapter, PersistenceAnnotationBeanPostProcessor, RequiredAnnotationBeanPostProcessor, ScriptFactoryPostProcessor

public interface InstantiationAwareBeanPostProcessor
extends BeanPostProcessor

Subinterface of BeanPostProcessor that adds a before-instantiation callback, and a callback after instantiation but before explicit properties are set or autowiring occurs.

Typically used to suppress default instantiation for specific target beans, for example to create proxies with special TargetSources (pooling targets, lazily initializing targets, etc), or to implement additional injection strategies such as field injection.

NOTE: This interface is a special purpose interface, mainly for internal use within the framework. It is recommended to implement the plain BeanPostProcessor interface as far as possible, or to derive from InstantiationAwareBeanPostProcessorAdapter in order to be shielded from extensions to this interface.

Since:
1.2
Author:
Juergen Hoeller, Rod Johnson
See Also:
AbstractAutoProxyCreator.setCustomTargetSourceCreators(org.springframework.aop.framework.autoproxy.TargetSourceCreator[]), LazyInitTargetSourceCreator

Method Summary
 boolean postProcessAfterInstantiation(Object bean, String beanName)
          Perform operations after the bean has been instantiated, via a constructor or factory method, but before Spring property population (from explicit properties or autowiring) occurs.
 Object postProcessBeforeInstantiation(Class beanClass, String beanName)
          Apply this BeanPostProcessor before the target bean gets instantiated.
 PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName)
          Post-process the given property values before the factory applies them to the given bean.
 
Methods inherited from interface org.springframework.beans.factory.config.BeanPostProcessor
postProcessAfterInitialization, postProcessBeforeInitialization
 

Method Detail

postProcessBeforeInstantiation

Object postProcessBeforeInstantiation(Class beanClass,
                                      String beanName)
                                      throws BeansException
Apply this BeanPostProcessor before the target bean gets instantiated. The returned bean object may be a proxy to use instead of the target bean, effectively suppressing default instantiation of the target bean.

If a non-null object is returned by this method, the bean creation process will be short-circuited. The only further processing applied is the BeanPostProcessor.postProcessAfterInitialization(java.lang.Object, java.lang.String) callback from the configured BeanPostProcessors.

This callback will only be applied to bean definitions with a bean class. In particular, it will not be applied to beans with a "factory-method".

Post-processors may implement the extended SmartInstantiationAwareBeanPostProcessor interface in order to predict the type of the bean object that they are going to return here.

Parameters:
beanClass - the class of the bean to be instantiated
beanName - the name of the bean
Returns:
the bean object to expose instead of a default instance of the target bean, or null to proceed with default instantiation
Throws:
BeansException - in case of errors
See Also:
AbstractBeanDefinition.hasBeanClass(), AbstractBeanDefinition.getFactoryMethodName()

postProcessAfterInstantiation

boolean postProcessAfterInstantiation(Object bean,
                                      String beanName)
                                      throws BeansException
Perform operations after the bean has been instantiated, via a constructor or factory method, but before Spring property population (from explicit properties or autowiring) occurs.

Parameters:
bean - the bean instance created, but whose properties have not yet been set
beanName - the name of the bean
Returns:
true if properties should be set on the bean; false if property population should be skipped. Normal implementations should return true. Returning false will also prevent any subsequent InstantiationAwareBeanPostProcessor instances being invoked on this bean instance.
Throws:
BeansException - in case of errors

postProcessPropertyValues

PropertyValues postProcessPropertyValues(PropertyValues pvs,
                                         PropertyDescriptor[] pds,
                                         Object bean,
                                         String beanName)
                                         throws BeansException
Post-process the given property values before the factory applies them to the given bean. Allows for checking whether all dependencies have been satisfied, for example based on a "Required" annotation on bean property setters.

Also allows for replacing the property values to apply, typically through creating a new MutablePropertyValues instance based on the original PropertyValues, adding or removing specific values.

Parameters:
pvs - the property values that the factory is about to apply (never null)
pds - the relevant property descriptors for the target bean (with ignored dependency types - which the factory handles specifically - already filtered out)
bean - the bean instance created, but whose properties have not yet been set
beanName - the name of the bean
Returns:
the actual property values to apply to to the given bean (can be the passed-in PropertyValues instance), or null to skip property population
Throws:
BeansException - in case of errors
See Also:
MutablePropertyValues

The Spring Framework

Copyright © 2002-2007 The Spring Framework.