AutowireCapableBeanFactory在BeanFactory基础上实现了对存在实例的管理.可以使用这个接口集成其它框架,捆绑并填充并不由Spring管理生命周期并已存在的实例.像集成WebWork的Actions 和Tapestry Page就很实用.

一般应用开发者不会使用这个接口,所以像ApplicationContext这样的外观实现类不会实现这个接口,如果真手痒痒可以通过ApplicationContext的getAutowireCapableBeanFactory接口获取.

AutowireCapableBeanFactory源码 具体:

1、总共5个静态不可变常量来指明装配策略,其中一个常量被Spring3.0废弃、一个常量表示没有自动装配,另外3个常量指明不同的装配策略——根据名称、根据类型、根据构造方法。

2、8个跟自动装配有关的方法,实在是繁杂,具体的意义我们研究类的时候再分辨吧。

3、2个执行BeanPostProcessors的方法。

4、2个分解指定依赖的方法

总结:这个工厂接口继承自BeanFacotory,它扩展了自动装配的功能,根据类定义BeanDefinition装配Bean、执行前、后处理器等。

/*** Extension of the {@link 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.** <p>This subinterface of BeanFactory is not meant to be used in normal* application code: stick to {@link org.springframework.beans.factory.BeanFactory}* or {@link org.springframework.beans.factory.ListableBeanFactory} for* typical use cases.** <p>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.** <p>Note that this interface is not implemented by* {@link org.springframework.context.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* {@link org.springframework.context.ApplicationContext#getAutowireCapableBeanFactory()}* method.** <p>You may also implement the {@link org.springframework.beans.factory.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.** @author Juergen Hoeller* @since 04.12.2003* @see org.springframework.beans.factory.BeanFactoryAware* @see org.springframework.beans.factory.config.ConfigurableListableBeanFactory* @see org.springframework.context.ApplicationContext#getAutowireCapableBeanFactory()*/
public interface AutowireCapableBeanFactory extends BeanFactory {/*** Constant that indicates no externally defined autowiring. Note that* BeanFactoryAware etc and annotation-driven injection will still be applied.* @see #createBean* @see #autowire* @see #autowireBeanProperties*///  这个常量表明工厂没有自动装配的Beanint AUTOWIRE_NO = 0;/*** Constant that indicates autowiring bean properties by name* (applying to all bean property setters).* @see #createBean* @see #autowire* @see #autowireBeanProperties*/// 表明根据名称自动装配int AUTOWIRE_BY_NAME = 1;/*** Constant that indicates autowiring bean properties by type* (applying to all bean property setters).* @see #createBean* @see #autowire* @see #autowireBeanProperties*/// 表明根据类型自动装配int AUTOWIRE_BY_TYPE = 2;/*** Constant that indicates autowiring the greediest constructor that* can be satisfied (involves resolving the appropriate constructor).* @see #createBean* @see #autowire*/// 表明根据构造方法快速装配int AUTOWIRE_CONSTRUCTOR = 3;/*** Constant that indicates determining an appropriate autowire strategy* through introspection of the bean class.* @see #createBean* @see #autowire* @deprecated as of Spring 3.0: If you are using mixed autowiring strategies,* prefer annotation-based autowiring for clearer demarcation of autowiring needs.*/@Deprecated// 表明通过Bean的class的内部来自动装配(有没翻译错...)Spring3.0被弃用。int AUTOWIRE_AUTODETECT = 4;//-------------------------------------------------------------------------// Typical methods for creating and populating external bean instances// 创建和填充外部bean实例的典型方法//-------------------------------------------------------------------------/*** Fully create a new bean instance of the given class.* <p>Performs full initialization of the bean, including all applicable* {@link BeanPostProcessor BeanPostProcessors}.* <p>Note: This is intended for creating a fresh instance, populating annotated* fields and methods as well as applying all standard bean initialization callbacks.* It does <i>not</> imply traditional by-name or by-type autowiring of properties;* use {@link #createBean(Class, int, boolean)} for those purposes.* @param beanClass the class of the bean to create* @return the new bean instance* @throws BeansException if instantiation or wiring failed*/<T> T createBean(Class<T> beanClass) throws BeansException;/*** Populate the given bean instance through applying after-instantiation callbacks* and bean property post-processing (e.g. for annotation-driven injection).* <p>Note: This is essentially intended for (re-)populating annotated fields and* methods, either for new instances or for deserialized instances. It does* <i>not</i> imply traditional by-name or by-type autowiring of properties;* use {@link #autowireBeanProperties} for those purposes.* @param existingBean the existing bean instance* @throws BeansException if wiring failed*/// 使用autowireBeanProperties装配属性void autowireBean(Object existingBean) throws BeansException;/*** Configure the given raw bean: autowiring bean properties, applying* bean property values, applying factory callbacks such as {@code setBeanName}* and {@code setBeanFactory}, and also applying all bean post processors* (including ones which might wrap the given raw bean).* <p>This is effectively a superset of what {@link #initializeBean} provides,* fully applying the configuration specified by the corresponding bean definition.* <b>Note: This method requires a bean definition for the given name!</b>* @param existingBean the existing bean instance* @param beanName the name of the bean, to be passed to it if necessary* (a bean definition of that name has to be available)* @return the bean instance to use, either the original or a wrapped one* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException* if there is no bean definition with the given name* @throws BeansException if the initialization failed* @see #initializeBean*/// 自动装配属性,填充属性值,使用诸如setBeanName,setBeanFactory这样的工厂回调填充属性,最好还要调用post processorObject configureBean(Object existingBean, String beanName) throws BeansException;/*** Resolve the specified dependency against the beans defined in this factory.* @param descriptor the descriptor for the dependency* @param beanName the name of the bean which declares the present dependency* @return the resolved object, or {@code null} if none found* @throws BeansException if dependency resolution failed*/Object resolveDependency(DependencyDescriptor descriptor, String beanName) throws BeansException;//-------------------------------------------------------------------------// Specialized methods for fine-grained control over the bean lifecycle// 在bean的生命周期进行细粒度控制的专门方法//-------------------------------------------------------------------------/*** Fully create a new bean instance of the given class with the specified* autowire strategy. All constants defined in this interface are supported here.* <p>Performs full initialization of the bean, including all applicable* {@link BeanPostProcessor BeanPostProcessors}. This is effectively a superset* of what {@link #autowire} provides, adding {@link #initializeBean} behavior.* @param beanClass the class of the bean to create* @param autowireMode by name or type, using the constants in this interface* @param dependencyCheck whether to perform a dependency check for objects* (not applicable to autowiring a constructor, thus ignored there)* @return the new bean instance* @throws BeansException if instantiation or wiring failed* @see #AUTOWIRE_NO* @see #AUTOWIRE_BY_NAME* @see #AUTOWIRE_BY_TYPE* @see #AUTOWIRE_CONSTRUCTOR*/// 会执行bean完整的初始化,包括BeanPostProcessors和initializeBeanObject createBean(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 {@code AUTOWIRE_NO} in order to just apply* before-instantiation callbacks (e.g. for annotation-driven injection).* <p>Does <i>not</i> apply standard {@link BeanPostProcessor BeanPostProcessors}* callbacks or perform any further initialization of the bean. This interface* offers distinct, fine-grained operations for those purposes, for example* {@link #initializeBean}. However, {@link InstantiationAwareBeanPostProcessor}* callbacks are applied, if applicable to the construction of the instance.* @param beanClass the class of the bean to instantiate* @param autowireMode by name or type, using the constants in this interface* @param dependencyCheck whether to perform a dependency check for object* references in the bean instance (not applicable to autowiring a constructor,* thus ignored there)* @return the new bean instance* @throws BeansException if instantiation or wiring failed* @see #AUTOWIRE_NO* @see #AUTOWIRE_BY_NAME* @see #AUTOWIRE_BY_TYPE* @see #AUTOWIRE_CONSTRUCTOR* @see #AUTOWIRE_AUTODETECT* @see #initializeBean* @see #applyBeanPostProcessorsBeforeInitialization* @see #applyBeanPostProcessorsAfterInitialization*/Object autowire(Class<?> beanClass, int autowireMode, boolean dependencyCheck) throws BeansException;/*** Autowire the bean properties of the given bean instance by name or type.* Can also be invoked with {@code AUTOWIRE_NO} in order to just apply* after-instantiation callbacks (e.g. for annotation-driven injection).* <p>Does <i>not</i> apply standard {@link BeanPostProcessor BeanPostProcessors}* callbacks or perform any further initialization of the bean. This interface* offers distinct, fine-grained operations for those purposes, for example* {@link #initializeBean}. However, {@link InstantiationAwareBeanPostProcessor}* callbacks are applied, if applicable to the configuration of the instance.* @param existingBean the existing bean instance* @param autowireMode by name or type, using the constants in this interface* @param dependencyCheck whether to perform a dependency check for object* references in the bean instance* @throws BeansException if wiring failed* @see #AUTOWIRE_BY_NAME* @see #AUTOWIRE_BY_TYPE* @see #AUTOWIRE_NO*/void autowireBeanProperties(Object existingBean, int autowireMode, boolean dependencyCheck)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.* <p>This method does <i>not</i> autowire bean properties; it just applies* explicitly defined property values. Use the {@link #autowireBeanProperties}* method to autowire an existing bean instance.* <b>Note: This method requires a bean definition for the given name!</b>* <p>Does <i>not</i> apply standard {@link BeanPostProcessor BeanPostProcessors}* callbacks or perform any further initialization of the bean. This interface* offers distinct, fine-grained operations for those purposes, for example* {@link #initializeBean}. However, {@link InstantiationAwareBeanPostProcessor}* callbacks are applied, if applicable to the configuration of the instance.* @param existingBean the existing bean instance* @param beanName the name of the bean definition in the bean factory* (a bean definition of that name has to be available)* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException* if there is no bean definition with the given name* @throws BeansException if applying the property values failed* @see #autowireBeanProperties*/void applyBeanPropertyValues(Object existingBean, String beanName) throws BeansException;/*** Initialize the given raw bean, applying factory callbacks* such as {@code setBeanName} and {@code setBeanFactory},* also applying all bean post processors (including ones which* might wrap the given raw bean).* <p>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.* @param existingBean the existing bean instance* @param beanName the name of the bean, to be passed to it if necessary* (only passed to {@link BeanPostProcessor BeanPostProcessors})* @return the bean instance to use, either the original or a wrapped one* @throws BeansException if the initialization failed*/Object initializeBean(Object existingBean, String beanName) throws BeansException;/*** Apply {@link BeanPostProcessor BeanPostProcessors} to the given existing bean* instance, invoking their {@code postProcessBeforeInitialization} methods.* The returned bean instance may be a wrapper around the original.* @param existingBean the new bean instance* @param beanName the name of the bean* @return the bean instance to use, either the original or a wrapped one* @throws BeansException if any post-processing failed* @see BeanPostProcessor#postProcessBeforeInitialization*/Object applyBeanPostProcessorsBeforeInitialization(Object existingBean, String beanName)throws BeansException;/*** Apply {@link BeanPostProcessor BeanPostProcessors} to the given existing bean* instance, invoking their {@code postProcessAfterInitialization} methods.* The returned bean instance may be a wrapper around the original.* @param existingBean the new bean instance* @param beanName the name of the bean* @return the bean instance to use, either the original or a wrapped one* @throws BeansException if any post-processing failed* @see BeanPostProcessor#postProcessAfterInitialization*/Object applyBeanPostProcessorsAfterInitialization(Object existingBean, String beanName)throws BeansException;/*** Destroy the given bean instance (typically coming from {@link #createBean}),* applying the {@link org.springframework.beans.factory.DisposableBean} contract as well as* registered {@link DestructionAwareBeanPostProcessor DestructionAwareBeanPostProcessors}.* <p>Any exception that arises during destruction should be caught* and logged instead of propagated to the caller of this method.* @param existingBean the bean instance to destroy*/void destroyBean(Object existingBean);/*** Resolve the specified dependency against the beans defined in this factory.* @param descriptor the descriptor for the dependency* @param beanName the name of the bean which declares the present dependency* @param autowiredBeanNames a Set that all names of autowired beans (used for* resolving the present dependency) are supposed to be added to* @param typeConverter the TypeConverter to use for populating arrays and* collections* @return the resolved object, or {@code null} if none found* @throws BeansException if dependency resolution failed*/Object resolveDependency(DependencyDescriptor descriptor, String beanName,Set<String> autowiredBeanNames, TypeConverter typeConverter) throws BeansException;}

AutowireCapableBeanFactory接口相关推荐

  1. Spring 框架的设计理念与设计模式分析

    Spring 的骨骼架构 Spring 总共有十几个组件,但是真正核心的组件只有几个,下面是 Spring 框架的总体架构图: 图 1 .Spring 框架的总体架构图 从上图中可以看出 Spring ...

  2. (转)spring源码解析,spring工作原理

    转自:https://www.ibm.com/developerworks/cn/java/j-lo-spring-principle/ Spring 的骨骼架构 Spring 总共有十几个组件,但是 ...

  3. 解决SpringBoot使用Quartz无法注入Bean的问题

    2019独角兽企业重金招聘Python工程师标准>>> 依赖 <dependency> <groupId>org.quartz-scheduler</g ...

  4. spring核心功能结构

    spring核心功能结构 Spring大约有20个模块,由1300多个不同的文件构成.这些模块可以分为: 核心容器.AOP和设备支持.数据访问与集成.Web组件.通信报文和集成测试等, 下面是 Spr ...

  5. Spring IOC流程源码分析

    一.Spring 核心容器 IOC初始化过程 Spring 核心之 IOC 容器初体验 IOC 与 DI IOC(Inversion of Control)控制反转:所谓控制反转,就是把原先我们代码里 ...

  6. Spring IOC实现原理

    一.IOC 容器:最主要是完成了完成对象的创建和依赖的管理注入等等. 所谓控制反转,就是把原先我们代码里面需要实现的对象创建.依赖的代码,反转给容器来帮忙实现.那么必然的我们需要创建一个容器,同时需要 ...

  7. Spring 核心容器类BeanFactory

    Spring Bean 的创建是典型的工厂模式,这一系列的Bean 工厂,也即IOC 容器为开发者管理对象间的依赖关系提供了很多便利和基础服务,在Spring 中有许多的IOC 容器的实现供用户选择和 ...

  8. 从源码深处体验Spring核心技术--IOC容器初体验

    开局经验之谈:可能从这一篇文章开始,小伙伴们都会有点晕车的感觉了,但是这个系列并不是只是介绍下spring表面的一些肤浅的东西,本系列的目的是为了让大家从源码层次深入理解Spring,这也是大家在未来 ...

  9. Spring框架的设计理念与设计模式分析

    spring设计原理 Spring框架的设计理念与设计模式分析 2016-1-27 by Damon 摘要:Spring作为现在最优秀的框架之一,被广泛的使用并有很多对其分析的文章.本文将从另外一个视 ...

最新文章

  1. JVM---本地方法接口和本地方法栈
  2. Fast CGI 工作原理
  3. 前端学习(635):字符串拼接
  4. Docker中安装Jenkins实时发布.net core 项目(二)
  5. python程序中想使用正则表达式_python中正则表达式的使用方法
  6. TensorFlow 中三种启动图用法
  7. python中提供怎样的内置库、可以用来创建用户界面_使用外部GUI库在Autodesk中创建用户界面可能会...
  8. 【clickhouse】ClickHouse基础、实践、调优全视角解析
  9. 网站制作---网站伪静态的介绍
  10. servlet实现mvc
  11. 盖雅工场完成3亿元C轮融资,由老虎环球基金领投...
  12. 微信开发者工具的最详细步骤如下:
  13. 黑群晖DSM7.1.0物理机安装教程
  14. Swagger与其他API文档编写工具对比
  15. java将页面转为pdf和pdf上添加盖章
  16. 字和词语联合训练的词向量模型
  17. 2022年危险化学品经营单位主要负责人最新解析及危险化学品经营单位主要负责人考试资料
  18. 诚聘软件过程工程师,高级软件工程师,软件开发工程师
  19. 使用 mitmproxy + python 做拦截代理 ( 后附猫眼跳转到美团验证码的拦截脚本 )
  20. 【RTX操作系统教程】第3章 初学RTX操作系统准备工作

热门文章

  1. 单片机小白学步系列(二十三) IO口原理知识补充:双向IO口、互补推挽、高阻态
  2. 怎么在终端启用python_在终端启动Python时报错的解决方案
  3. js粘贴板为什么获取不到图片信息_图床+typora,告别markdown中关于图片的困惑
  4. 如何区分网线是几类的_小移课堂 | 网线这样选,网速才能嗖嗖的!
  5. 计算机二级mysql是什么_计算机二级mysql考什么内容?
  6. python自动发邮件运行正常就是收不到邮件是为什么_python stmp module 163邮箱发送邮件不成功...
  7. 西门子plm_西门子的Teamcenter、TIA Portal、NX MCD是如何结合在一起的
  8. mmseg java_MMSeg中文分词算法
  9. python文本解析_如何通过python进行文本解析?
  10. android 系统倒计时显示时间,Android 依据系统时间整点、半点倒计时