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.pswp.cn/news/249516.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/249516.shtml
英文地址,請注明出處:http://en.pswp.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…