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

AutowiredAnnotationBeanPostProcessor (Spring Framework API 2.1) - Spring Framework 2.1.0 API 文档英文版


The Spring Framework

org.springframework.beans.factory.annotation
Class AutowiredAnnotationBeanPostProcessor

java.lang.Object
  extended by org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter
      extended by org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor
All Implemented Interfaces:
BeanFactoryAware, BeanPostProcessor, InstantiationAwareBeanPostProcessor, SmartInstantiationAwareBeanPostProcessor

public class AutowiredAnnotationBeanPostProcessor
extends InstantiationAwareBeanPostProcessorAdapter
implements BeanFactoryAware

BeanPostProcessor implementation that autowires annotated fields, setter methods and arbitrary config methods. Such members to be injected are detected through a Java 5 annotation: by default, Spring's Autowired annotation.

Only one constructor (at max) of any given bean class may carry this annotation, indicating the constructor to autowire when used as a Spring bean. Such a constructor does not have to be public.

Fields are injected right after construction of a bean, before any config methods are invoked. Such a config field does not have to be public.

Config methods may have an arbitrary name and any number of arguments; each of those arguments will be autowired with a matching bean in the Spring container. Bean property setter methods are effectively just a special case of such a general config method. Such config methods do not have to be public.

Since:
2.1
Author:
Juergen Hoeller
See Also:
setAutowiredAnnotationType(java.lang.Class), Autowired, CommonAnnotationBeanPostProcessor

Constructor Summary
AutowiredAnnotationBeanPostProcessor()
           
 
Method Summary
 Constructor determineConstructor(Class beanClass, String beanName)
          Determine the constructor to use for the given bean.
protected  Class<? extends Annotation> getAutowiredAnnotationType()
          Return the 'autowired' annotation type.
protected  Object getBeanOfType(Class type)
          Obtain a unique bean of the given type.
 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.
 void setAutowiredAnnotationType(Class<? extends Annotation> autowiredAnnotationType)
          Set the 'autowired' annotation type, to be used on constructors, fields, setter methods and arbitrary config methods.
 void setBeanFactory(BeanFactory beanFactory)
          Callback that supplies the owning factory to a bean instance.
 
Methods inherited from class org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter
postProcessAfterInitialization, postProcessBeforeInitialization, postProcessBeforeInstantiation, postProcessPropertyValues, predictBeanType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AutowiredAnnotationBeanPostProcessor

public AutowiredAnnotationBeanPostProcessor()
Method Detail

setAutowiredAnnotationType

public void setAutowiredAnnotationType(Class<? extends Annotation> autowiredAnnotationType)
Set the 'autowired' annotation type, to be used on constructors, fields, setter methods and arbitrary config methods.

The default autowired annotation type is the Spring-provided Autowired annotation.

This setter property exists so that developers can provide their own (non-Spring-specific) annotation type to indicate that a member is supposed to be autowired.


getAutowiredAnnotationType

protected Class<? extends Annotation> getAutowiredAnnotationType()
Return the 'autowired' annotation type.


setBeanFactory

public void setBeanFactory(BeanFactory beanFactory)
                    throws BeansException
Description copied from interface: BeanFactoryAware
Callback that supplies the owning factory to a bean instance.

Invoked after the population of normal bean properties but before an initialization callback such as InitializingBean.afterPropertiesSet() or a custom init-method.

Specified by:
setBeanFactory in interface BeanFactoryAware
Parameters:
beanFactory - owning BeanFactory (never null). The bean can immediately call methods on the factory.
Throws:
BeansException - in case of initialization errors
See Also:
BeanInitializationException

determineConstructor

public Constructor determineConstructor(Class beanClass,
                                        String beanName)
                                 throws BeansException
Description copied from interface: SmartInstantiationAwareBeanPostProcessor
Determine the constructor to use for the given bean.

Specified by:
determineConstructor in interface SmartInstantiationAwareBeanPostProcessor
Overrides:
determineConstructor in class InstantiationAwareBeanPostProcessorAdapter
Parameters:
beanClass - the raw class of the bean
beanName - the name of the bean
Returns:
the constructor to use, or null if none specified
Throws:
BeansException - in case of errors

postProcessAfterInstantiation

public boolean postProcessAfterInstantiation(Object bean,
                                             String beanName)
                                      throws BeansException
Description copied from interface: InstantiationAwareBeanPostProcessor
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.

Specified by:
postProcessAfterInstantiation in interface InstantiationAwareBeanPostProcessor
Overrides:
postProcessAfterInstantiation in class InstantiationAwareBeanPostProcessorAdapter
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

getBeanOfType

protected Object getBeanOfType(Class type)
                        throws BeansException
Obtain a unique bean of the given type.

Parameters:
type - the type of the bean
Returns:
the target bean (never null)
Throws:
BeansException - if we failed to obtain the bean

The Spring Framework

Copyright © 2002-2007 The Spring Framework.