AutowireCapableBeanFactory接口

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;}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/249516.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

外观模式

一、什么是外观模式   有些人可能炒过股票&#xff0c;但其实大部分人都不太懂&#xff0c;这种没有足够了解证券知识的情况下做股票是很容易亏钱的&#xff0c;刚开始炒股肯定都会想&#xff0c;如果有个懂行的帮帮手就好&#xff0c;其实基金就是个好帮手&#xff0c;支付宝…

OC内存管理

OC内存管理 一、基本原理 &#xff08;一&#xff09;为什么要进行内存管理。 由于移动设备的内存极其有限&#xff0c;所以每个APP所占的内存也是有限制的&#xff0c;当app所占用的内存较多时&#xff0c;系统就会发出内存警告&#xff0c;这时需要回收一些不需要再继续使用的…

cf1132E. Knapsack(搜索)

题意 题目链接 Sol 看了status里面最短的代码。。感觉自己真是菜的一批。。直接爆搜居然可以过&#xff1f;。。但是现在还没终测所以可能会fst。。 #include<bits/stdc.h> #define Pair pair<int, int> #define MP(x, y) make_pair(x, y) #define fi first #defi…

ConfigurableListableBeanFactory

ConfigurableListableBeanFactory 提供bean definition的解析,注册功能,再对单例来个预加载(解决循环依赖问题). 貌似我们一般开发就会直接定义这么个接口了事.而不是像Spring这样先根据使用情况细分那么多,到这边再合并 ConfigurableListableBeanFactory具体&#xff1a; 1、…

焦旭超 201771010109《面向对象程序设计课程学习进度条》

《2018面向对象程序设计&#xff08;java&#xff09;课程学习进度条》 周次 &#xff08;阅读/编写&#xff09;代码行数 发布博客量/博客评论量 课堂/课余学习时间&#xff08;小时&#xff09; 最满意的编程任务 第一周 50/20 1/0 6/4 九九乘法表 第二周 90/5…

面试题集锦

1. L1范式和L2范式的区别 (1) L1范式是对应参数向量绝对值之和 (2) L1范式具有稀疏性 (3) L1范式可以用来作为特征选择&#xff0c;并且可解释性较强&#xff08;这里的原理是在实际Loss function 中都需要求最小值&#xff0c;根据L1的定义可知L1最小值只有0&#xff0c;故可以…

Spring注解配置工作原理源码解析

一、背景知识 在【Spring实战】Spring容器初始化完成后执行初始化数据方法一文中说要分析其实现原理&#xff0c;于是就从源码中寻找答案&#xff0c;看源码容易跑偏&#xff0c;因此应当有个主线&#xff0c;或者带着问题、目标去看&#xff0c;这样才能最大限度的提升自身代…

halt

关机 init 0 reboot init6 shutdown -r now 重启 -h now 关机 转载于:https://www.cnblogs.com/todayORtomorrow/p/10486123.html

Spring--Context

应用上下文 Spring通过应用上下文&#xff08;Application Context&#xff09;装载bean的定义并把它们组装起来。Spring应用上下文全权负责对象的创建和组装。Spring自带了多种应用上下文的实现&#xff0c;它们之间主要的区别仅仅在于如何加载配置。 1.AnnotationConfigApp…

了解PID控制

2019-03-07 【小记】 了解PID控制 比例 - 积分 - 微分 积分 --- 记忆过去 比例 --- 了解现在 微分 --- 预测未来 转载于:https://www.cnblogs.com/skullboyer/p/10487884.html

program collections

Java byte & 0xff byte[] b new byte[1];b[0] -127;System.out.println("b[0]:"b[0]"; b[0]&0xff:"(b[0] & 0xff));//output:b[0]:-127; b[0]&0xff:129计算机内二进制都是补码形式存储&#xff1a; b[0]: 补码&#xff0c;10000001&…

软件测试问题

1.什么是兼容性测试?兼容性测试侧重哪些方面? 主要检验的是软件的可移植性&#xff0c;检查软件在不同的硬件平台软件平台上是否可以正常的运行。 细分会有&#xff1a;平台的兼容&#xff0c;网络兼容&#xff0c;数据库兼容&#xff0c;数据格式的兼容等。 2.常用的测试方法…

Spring注解源码分析

我们知道如果想使用spring注解你需要在applicationContext.xml配置文件中设置context:component-scan base-packagexxx’这样spring会帮助我们扫描你所设置的目录里面所有的Bean&#xff0c;如果Bean上面有相应的Service,Controller注解&#xff08;当然还有其他的&#xff0c;…

linux查看和修改PATH环境变量的方法

查看PATH&#xff1a;echo $PATH以添加mongodb server为列修改方法一&#xff1a;export PATH/usr/local/mongodb/bin:$PATH//配置完后可以通过echo $PATH查看配置结果。生效方法&#xff1a;立即生效有效期限&#xff1a;临时改变&#xff0c;只能在当前的终端窗口中有效&…

GLog 初始化说明

#include <iostream> #include <glog/logging.h>int main(int argc, char* argv[]) {google::InitGoogleLogging(argv[0]);FLAGS_logtostderr false; // 是否将日志输出到stderr而非文件。FLAGS_alsologtostderr false; //是否将日志输出到文件和stderr&#xff…

Spring ConfigurationClassPostProcessor Bean解析及自注册过程

一bean的自注册过程 二,自注册过程说明 1 configurationclassparser解析流程 1、处理PropertySources注解&#xff0c;配置信息的解析 2、处理ComponentScan注解&#xff1a;使用ComponentScanAnnotationParser扫描basePackage下的需要解析的类(SpringBootApplication注解也包…

新华社:华尔街专家警告2019年美股或面临剧烈调整

新华社&#xff1a;华尔街专家警告2019年美股或面临剧烈调整 2018年08月14日 12:34 新华社新浪财经APP缩小字体放大字体收藏微博微信分享转载于:https://www.cnblogs.com/hjlweilong/p/9664677.html

java定义注解

小伙伴们。今天我们来说说注解、标志 。针对java不同版本来说&#xff0c;注解的出现是在jdk1.5 但是在jdk1.5版本使用注解必须继续类的方法的重写&#xff0c;不能用于实现的接口中的方法实现&#xff0c;在jdk1.6环境下对于继续和实现都是用。 jdk1.5版本内置了三种标准的注…

2018.09.18 while循环

** "loop" 循环 注意要有引号。 **pass 过 #打印 1-100start 1 while start < 101:print("loop",start)start 1 #打印1-49&#xff0c;81-100. 60-80的平方start 1 while start <101 :if start >49 and start < 60:passelif start >5…

2019第二周作业

基础作业 实验代码 #include<stdlib.h> int main(void) {FILE*fp;int num[4],i,b,max;char op;if((fpfopen("c:\\tmj.txt","r"))NULL){ printf("File open error!\n"); exit(0);}for(i0;i<4;i){fscanf(fp,"%d%c",&nu…