Save This Page
Home » spring-framework-2.5.5-with-dependencies » org.springframework » beans » factory » support » [javadoc | source]
org.springframework.beans.factory.support
abstract public class: AbstractAutowireCapableBeanFactory [javadoc | source]
java.lang.Object
   org.springframework.core.SimpleAliasRegistry
      org.springframework.beans.factory.support.DefaultSingletonBeanRegistry
         org.springframework.beans.factory.support.FactoryBeanRegistrySupport
            org.springframework.beans.factory.support.AbstractBeanFactory
               org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory

All Implemented Interfaces:
    AutowireCapableBeanFactory, ConfigurableBeanFactory, SingletonBeanRegistry, AliasRegistry

Direct Known Subclasses:
    DefaultListableBeanFactory, XmlBeanFactory

Abstract bean factory superclass that implements default bean creation, with the full capabilities specified by the RootBeanDefinition class. Implements the org.springframework.beans.factory.config.AutowireCapableBeanFactory interface in addition to AbstractBeanFactory's #createBean method.

Provides bean creation (with constructor resolution), property population, wiring (including autowiring), and initialization. Handles runtime bean references, resolves managed collections, calls initialization methods, etc. Supports autowiring constructors, properties by name, and properties by type.

The main template method to be implemented by subclasses is #resolveDependency(DependencyDescriptor, String, Set, TypeConverter) , used for autowiring by type. In case of a factory which is capable of searching its bean definitions, matching beans will typically be implemented through such a search. For other factory styles, simplified matching algorithms can be implemented.

Note that this class does not assume or implement bean definition registry capabilities. See DefaultListableBeanFactory for an implementation of the org.springframework.beans.factory.ListableBeanFactory and BeanDefinitionRegistry interfaces, which represent the API and SPI view of such a factory, respectively.

Fields inherited from org.springframework.beans.factory.support.DefaultSingletonBeanRegistry:
NULL_OBJECT,  logger
Constructor:
 public AbstractAutowireCapableBeanFactory() 
 public AbstractAutowireCapableBeanFactory(BeanFactory parentBeanFactory) 
    Create a new AbstractAutowireCapableBeanFactory with the given parent.
    Parameters:
    parentBeanFactory - parent bean factory, or null if none
Method from org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory Summary:
applyBeanPostProcessorsAfterInitialization,   applyBeanPostProcessorsBeforeInitialization,   applyBeanPostProcessorsBeforeInstantiation,   applyBeanPropertyValues,   applyMergedBeanDefinitionPostProcessors,   applyPropertyValues,   autowire,   autowireBean,   autowireBeanProperties,   autowireByName,   autowireByType,   autowireConstructor,   checkDependencies,   configureBean,   copyConfigurationFrom,   createBean,   createBean,   createBean,   createBeanInstance,   determineConstructorsFromBeanPostProcessors,   doCreateBean,   filterPropertyDescriptorsForDependencyCheck,   getEarlyBeanReference,   getInstantiationStrategy,   getTypeForFactoryBean,   getTypeForFactoryMethod,   ignoreDependencyInterface,   ignoreDependencyType,   initializeBean,   initializeBean,   instantiateBean,   instantiateUsingFactoryMethod,   invokeCustomInitMethod,   invokeInitMethods,   isExcludedFromDependencyCheck,   populateBean,   postProcessObjectFromFactoryBean,   predictBeanType,   removeSingleton,   resolveBeforeInstantiation,   resolveDependency,   setAllowCircularReferences,   setAllowRawInjectionDespiteWrapping,   setInstantiationStrategy,   unsatisfiedNonSimpleProperties
Methods from org.springframework.beans.factory.support.AbstractBeanFactory:
addBeanPostProcessor,   addPropertyEditorRegistrar,   afterPrototypeCreation,   beforePrototypeCreation,   checkMergedBeanDefinition,   clearMergedBeanDefinition,   containsBean,   containsBeanDefinition,   containsLocalBean,   copyConfigurationFrom,   createBean,   destroyBean,   destroyBean,   destroyScopedBean,   doGetBean,   getAliases,   getBean,   getBean,   getBean,   getBean,   getBeanClassLoader,   getBeanDefinition,   getBeanPostProcessorCount,   getBeanPostProcessors,   getCustomEditors,   getCustomTypeConverter,   getMergedBeanDefinition,   getMergedBeanDefinition,   getMergedBeanDefinition,   getMergedLocalBeanDefinition,   getObjectForBeanInstance,   getParentBeanFactory,   getPropertyEditorRegistrars,   getRegisteredScope,   getRegisteredScopeNames,   getTempClassLoader,   getType,   getTypeConverter,   getTypeForFactoryBean,   hasDestructionAwareBeanPostProcessors,   hasInstantiationAwareBeanPostProcessors,   initBeanWrapper,   isBeanEligibleForMetadataCaching,   isBeanNameInUse,   isCacheBeanMetadata,   isCurrentlyInCreation,   isFactoryBean,   isFactoryBean,   isPrototype,   isPrototypeCurrentlyInCreation,   isSingleton,   isTypeMatch,   markBeanAsCreated,   originalBeanName,   predictBeanType,   registerCustomEditor,   registerCustomEditor,   registerCustomEditors,   registerDisposableBeanIfNecessary,   registerScope,   removeSingletonIfCreatedForTypeCheckOnly,   requiresDestruction,   resolveBeanClass,   resolveBeanClass,   setBeanClassLoader,   setCacheBeanMetadata,   setParentBeanFactory,   setTempClassLoader,   setTypeConverter,   transformedBeanName
Methods from org.springframework.beans.factory.support.FactoryBeanRegistrySupport:
getCachedObjectForFactoryBean,   getFactoryBean,   getObjectFromFactoryBean,   getTypeForFactoryBean,   postProcessObjectFromFactoryBean,   removeSingleton
Methods from org.springframework.beans.factory.support.DefaultSingletonBeanRegistry:
addSingleton,   addSingletonFactory,   afterSingletonCreation,   beforeSingletonCreation,   containsSingleton,   destroyBean,   destroySingleton,   destroySingletons,   getDependenciesForBean,   getDependentBeans,   getSingleton,   getSingleton,   getSingleton,   getSingletonCount,   getSingletonMutex,   getSingletonNames,   hasDependentBean,   isSingletonCurrentlyInCreation,   onSuppressedException,   registerDependentBean,   registerDisposableBean,   registerSingleton,   removeSingleton
Methods from org.springframework.core.SimpleAliasRegistry:
allowAliasOverriding,   canonicalName,   getAliases,   isAlias,   registerAlias,   removeAlias,   resolveAliases
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory Detail:
 public Object applyBeanPostProcessorsAfterInitialization(Object existingBean,
    String beanName) throws BeansException 
 public Object applyBeanPostProcessorsBeforeInitialization(Object existingBean,
    String beanName) throws BeansException 
 protected Object applyBeanPostProcessorsBeforeInstantiation(Class beanClass,
    String beanName) throws BeansException 
    Apply InstantiationAwareBeanPostProcessors to the specified bean definition (by class and name), invoking their postProcessBeforeInstantiation methods.

    Any returned object will be used as the bean instead of actually instantiating the target bean. A null return value from the post-processor will result in the target bean being instantiated.

 public  void applyBeanPropertyValues(Object existingBean,
    String beanName) throws BeansException 
 protected  void applyMergedBeanDefinitionPostProcessors(RootBeanDefinition mbd,
    Class beanType,
    String beanName) throws BeansException 
    Apply MergedBeanDefinitionPostProcessors to the specified bean definition, invoking their postProcessMergedBeanDefinition methods.
 protected  void applyPropertyValues(String beanName,
    BeanDefinition mbd,
    BeanWrapper bw,
    PropertyValues pvs) 
    Apply the given property values, resolving any runtime references to other beans in this bean factory. Must use deep copy, so we don't permanently modify this property.
 public Object autowire(Class beanClass,
    int autowireMode,
    boolean dependencyCheck) throws BeansException 
 public  void autowireBean(Object existingBean) 
 public  void autowireBeanProperties(Object existingBean,
    int autowireMode,
    boolean dependencyCheck) throws BeansException 
 protected  void autowireByName(String beanName,
    AbstractBeanDefinition mbd,
    BeanWrapper bw,
    MutablePropertyValues pvs) 
    Fill in any missing property values with references to other beans in this factory if autowire is set to "byName".
 protected  void autowireByType(String beanName,
    AbstractBeanDefinition mbd,
    BeanWrapper bw,
    MutablePropertyValues pvs) 
    Abstract method defining "autowire by type" (bean properties by type) behavior.

    This is like PicoContainer default, in which there must be exactly one bean of the property type in the bean factory. This makes bean factories simple to configure for small namespaces, but doesn't work as well as standard Spring behavior for bigger applications.

 protected BeanWrapper autowireConstructor(String beanName,
    RootBeanDefinition mbd,
    Constructor[] ctors,
    Object[] explicitArgs) 
    "autowire constructor" (with constructor arguments by type) behavior. Also applied if explicit constructor argument values are specified, matching all remaining arguments with beans from the bean factory.

    This corresponds to constructor injection: In this mode, a Spring bean factory is able to host components that expect constructor-based dependency resolution.

 protected  void checkDependencies(String beanName,
    AbstractBeanDefinition mbd,
    PropertyDescriptor[] pds,
    PropertyValues pvs) throws UnsatisfiedDependencyException 
    Perform a dependency check that all properties exposed have been set, if desired. Dependency checks can be objects (collaborating beans), simple (primitives and String), or all (both).
 public Object configureBean(Object existingBean,
    String beanName) throws BeansException 
 public  void copyConfigurationFrom(ConfigurableBeanFactory otherFactory) 
 public Object createBean(Class beanClass) throws BeansException 
 public Object createBean(Class beanClass,
    int autowireMode,
    boolean dependencyCheck) throws BeansException 
 protected Object createBean(String beanName,
    RootBeanDefinition mbd,
    Object[] args) throws BeanCreationException 
    Central method of this class: creates a bean instance, populates the bean instance, applies post-processors, etc.
 protected BeanWrapper createBeanInstance(String beanName,
    RootBeanDefinition mbd,
    Object[] args) 
    Create a new instance for the specified bean, using an appropriate instantiation strategy: factory method, constructor autowiring, or simple instantiation.
 protected Constructor[] determineConstructorsFromBeanPostProcessors(Class beanClass,
    String beanName) throws BeansException 
 protected Object doCreateBean(String beanName,
    RootBeanDefinition mbd,
    Object[] args) 
    Actually create the specified bean. Pre-creation processing has already happened at this point, e.g. checking postProcessBeforeInstantiation callbacks.

    Differentiates between default bean instantiation, use of a factory method, and autowiring a constructor.

 protected PropertyDescriptor[] filterPropertyDescriptorsForDependencyCheck(BeanWrapper bw) 
    Extract a filtered set of PropertyDescriptors from the given BeanWrapper, excluding ignored dependency types or properties defined on ignored dependency interfaces.
 protected Object getEarlyBeanReference(String beanName,
    RootBeanDefinition mbd,
    Object bean) 
    Obtain a reference for early access to the specified bean, typically for the purpose of resolving a circular reference.
 protected InstantiationStrategy getInstantiationStrategy() 
    Return the instantiation strategy to use for creating bean instances.
 protected Class getTypeForFactoryBean(String beanName,
    RootBeanDefinition mbd) 
    This implementation checks the FactoryBean's getObjectType method on a plain instance of the FactoryBean, without bean properties applied yet. If this doesn't return a type yet, a full creation of the FactoryBean is used as fallback (through delegation to the superclass's implementation).

    The shortcut check for a FactoryBean is only applied in case of a singleton FactoryBean. If the FactoryBean instance itself is not kept as singleton, it will be fully created to check the type of its exposed object.

 protected Class getTypeForFactoryMethod(String beanName,
    RootBeanDefinition mbd,
    Class[] typesToMatch) 
    Determine the bean type for the given bean definition which is based on a factory method. Only called if there is no singleton instance registered for the target bean already.

    This implementation determines the type matching #createBean 's different creation strategies. As far as possible, we'll perform static type checking to avoid creation of the target bean.

 public  void ignoreDependencyInterface(Class ifc) 
    Ignore the given dependency interface for autowiring.

    This will typically be used by application contexts to register dependencies that are resolved in other ways, like BeanFactory through BeanFactoryAware or ApplicationContext through ApplicationContextAware.

    By default, only the BeanFactoryAware interface is ignored. For further types to ignore, invoke this method for each type.

 public  void ignoreDependencyType(Class type) 
    Ignore the given dependency type for autowiring: for example, String. Default is none.
 public Object initializeBean(Object existingBean,
    String beanName) 
 protected Object initializeBean(String beanName,
    Object bean,
    RootBeanDefinition mbd) 
    Initialize the given bean instance, applying factory callbacks as well as init methods and bean post processors.

    Called from #createBean for traditionally defined beans, and from #initializeBean for existing bean instances.

 protected BeanWrapper instantiateBean(String beanName,
    RootBeanDefinition mbd) 
    Instantiate the given bean using its default constructor.
 protected BeanWrapper instantiateUsingFactoryMethod(String beanName,
    RootBeanDefinition mbd,
    Object[] explicitArgs) 
    Instantiate the bean using a named factory method. The method may be static, if the mbd parameter specifies a class, rather than a factoryBean, or an instance variable on a factory object itself configured using Dependency Injection.
 protected  void invokeCustomInitMethod(String beanName,
    Object bean,
    String initMethodName,
    boolean enforceInitMethod) throws Throwable 
    Invoke the specified custom init method on the given bean. Called by invokeInitMethods.

    Can be overridden in subclasses for custom resolution of init methods with arguments.

 protected  void invokeInitMethods(String beanName,
    Object bean,
    RootBeanDefinition mbd) throws Throwable 
    Give a bean a chance to react now all its properties are set, and a chance to know about its owning bean factory (this object). This means checking whether the bean implements InitializingBean or defines a custom init method, and invoking the necessary callback(s) if it does.
 protected boolean isExcludedFromDependencyCheck(PropertyDescriptor pd) 
    Determine whether the given bean property is excluded from dependency checks.

    This implementation excludes properties defined by CGLIB and properties whose type matches an ignored dependency type or which are defined by an ignored dependency interface.

 protected  void populateBean(String beanName,
    AbstractBeanDefinition mbd,
    BeanWrapper bw) 
    Populate the bean instance in the given BeanWrapper with the property values from the bean definition.
 protected Object postProcessObjectFromFactoryBean(Object object,
    String beanName) 
    Applies the postProcessAfterInitialization callback of all registered BeanPostProcessors, giving them a chance to post-process the object obtained from FactoryBeans (for example, to auto-proxy them).
 protected Class predictBeanType(String beanName,
    RootBeanDefinition mbd,
    Class[] typesToMatch) 
 protected  void removeSingleton(String beanName) 
    Overridden to clear FactoryBean instance cache as well.
 protected Object resolveBeforeInstantiation(String beanName,
    RootBeanDefinition mbd) 
    Apply before-instantiation post-processors, resolving whether there is a before-instantiation shortcut for the specified bean.
 public Object resolveDependency(DependencyDescriptor descriptor,
    String beanName) throws BeansException 
 public  void setAllowCircularReferences(boolean allowCircularReferences) 
    Set whether to allow circular references between beans - and automatically try to resolve them.

    Note that circular reference resolution means that one of the involved beans will receive a reference to another bean that is not fully initialized yet. This can lead to subtle and not-so-subtle side effects on initialization; it does work fine for many scenarios, though.

    Default is "true". Turn this off to throw an exception when encountering a circular reference, disallowing them completely.

    NOTE: It is generally recommended to not rely on circular references between your beans. Refactor your application logic to have the two beans involved delegate to a third bean that encapsulates their common logic.

 public  void setAllowRawInjectionDespiteWrapping(boolean allowRawInjectionDespiteWrapping) 
    Set whether to allow the raw injection of a bean instance into some other bean's property, despite the injected bean eventually getting wrapped (for example, through AOP auto-proxying).

    This will only be used as a last resort in case of a circular reference that cannot be resolved otherwise: essentially, preferring a raw instance getting injected over a failure of the entire bean wiring process.

    Default is "false", as of Spring 2.0. Turn this on to allow for non-wrapped raw beans injected into some of your references, which was Spring 1.2's (arguably unclean) default behavior.

    NOTE: It is generally recommended to not rely on circular references between your beans, in particular with auto-proxying involved.

 public  void setInstantiationStrategy(InstantiationStrategy instantiationStrategy) 
    Set the instantiation strategy to use for creating bean instances. Default is CglibSubclassingInstantiationStrategy.
 protected String[] unsatisfiedNonSimpleProperties(AbstractBeanDefinition mbd,
    BeanWrapper bw) 
    Return an array of non-simple bean properties that are unsatisfied. These are probably unsatisfied references to other beans in the factory. Does not include simple properties like primitives or Strings.