configurablebeanfactory

在這里插入圖片描述
ConfigurableBeanFactory定義BeanFactory的配置.ConfigurableBeanFactory中定義了太多太多的api,比如類加載器,類型轉化,屬性編輯器,BeanPostProcessor,作用域,bean定義,處理bean依賴關系,合并其他ConfigurableBeanFactory,bean如何銷毀.

ConfigurableBeanFactory同時繼承了HierarchicalBeanFactory 和 SingletonBeanRegistry 這兩個接口,即同時繼承了分層和單例類注冊的功能。

具體:

1、2個靜態不可變常量分別代表單例類和原型類。

2、1個設置父工廠的方法,跟HierarchicalBeanFactory接口的getParentBeanFactory方法互補。

3、4個跟類加載器有關的方法:get/set工廠類加載器和get/set臨時類加載器。

4、2個設置、是否緩存元數據的方法(熱加載開關)。

5、11個處理Bean注冊、加載等細節的方法,包括:Bean表達式分解器、轉換服務、屬性編輯登記員、屬性編輯器、屬性編輯注冊器、類型轉換器、嵌入式的字符串分解器

6、2個處理Bean后處理器的方法。

7、3個跟注冊范圍相關的方法。

8、1個返回安全訪問上下文的方法、1個從其他的工廠復制相關的所有配置的方法。

9、2個跟Bean別名相關的方法、1個返回合并后的Bean定義的方法。

10、1個判斷是否為工廠Bean的方法、2個跟當前Bean創建時機相關的方法。

11、3個跟Bean依賴相關的方法、3個銷毀Bean相關的方法。

總結:這個巨大的工廠接口,繼承自HierarchicalBeanFactory 和 SingletonBeanRegistry 這兩個接口,并額外獨有37個方法!!!(看的我都快瘋了…)這37個方法包含了工廠創建、注冊一個Bean的眾多細節。這個工廠名為ConfigurableBeanFactory,真是名不虛傳!統計一下此時的ConfigurableBeanFactory的方法數吧。自有的37個方法、HierarchicalBeanFactory的2個方法、SingletonBeanRegistry的5個方法、爺爺接口BeanFactory的10個方法,共有54個方法!雖然方法繁多,還算井井有條!

/*** Configuration interface to be implemented by most bean factories. Provides* facilities to configure a bean factory, in addition to the bean factory* client methods in the {@link org.springframework.beans.factory.BeanFactory}* interface.** <p>This bean factory interface 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* needs. This extended interface is just meant to allow for framework-internal* plug'n'play and for special access to bean factory configuration methods.** @author Juergen Hoeller* @since 03.11.2003* @see org.springframework.beans.factory.BeanFactory* @see org.springframework.beans.factory.ListableBeanFactory* @see ConfigurableListableBeanFactory*/
/*** 定義BeanFactory的配置.* * 這邊定義了太多太多的api,比如類加載器,類型轉化,屬性編輯器,BeanPostProcessor,作用域,bean定義,處理bean依賴關系,合并其他ConfigurableBeanFactory,bean如何銷毀.* * @author DemoTransfer* @since 4.3*/
public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, SingletonBeanRegistry {//-------------------------------------------------------------------------// 定義了兩個作用域: 單例和原型.可以通過registerScope來添加.// SCOPE_SINGLETON,SCOPE_PROTOTYPE//-------------------------------------------------------------------------/*** Scope identifier for the standard singleton scope: "singleton".* Custom scopes can be added via {@code registerScope}.* @see #registerScope*///  單例String SCOPE_SINGLETON = "singleton";/*** Scope identifier for the standard prototype scope: "prototype".* Custom scopes can be added via {@code registerScope}.* @see #registerScope*///  原型String SCOPE_PROTOTYPE = "prototype";/*** Set the parent of this bean factory.* <p>Note that the parent cannot be changed: It should only be set outside* a constructor if it isn't available at the time of factory instantiation.* @param parentBeanFactory the parent BeanFactory* @throws IllegalStateException if this factory is already associated with* a parent BeanFactory* @see #getParentBeanFactory()*/// 父容器設置.而且一旦設置了就不讓修改/** 搭配HierarchicalBeanFactory接口的getParentBeanFactory方法*/void setParentBeanFactory(BeanFactory parentBeanFactory) throws IllegalStateException;/*** Set the class loader to use for loading bean classes.* Default is the thread context class loader.* <p>Note that this class loader will only apply to bean definitions* that do not carry a resolved bean class yet. This is the case as of* Spring 2.0 by default: Bean definitions only carry bean class names,* to be resolved once the factory processes the bean definition.* @param beanClassLoader the class loader to use,* or {@code null} to suggest the default class loader*/// 類加載器設置與獲取.默認使用當前線程中的類加載器/** 設置、返回工廠的類加載器*/void setBeanClassLoader(ClassLoader beanClassLoader);/*** Return this factory's class loader for loading bean classes.*/// 類加載器設置與獲取.默認使用當前線程中的類加載器ClassLoader getBeanClassLoader();/*** Specify a temporary ClassLoader to use for type matching purposes.* Default is none, simply using the standard bean ClassLoader.* <p>A temporary ClassLoader is usually just specified if* <i>load-time weaving</i> is involved, to make sure that actual bean* classes are loaded as lazily as possible. The temporary loader is* then removed once the BeanFactory completes its bootstrap phase.* @since 2.5*/// 為了類型匹配,搞個臨時類加載器.好在一般情況為null,使用上面定義的標準加載器/** 設置、返回一個臨時的類加載器*/void setTempClassLoader(ClassLoader tempClassLoader);/*** Return the temporary ClassLoader to use for type matching purposes,* if any.* @since 2.5*/// 為了類型匹配,搞個臨時類加載器.好在一般情況為null,使用上面定義的標準加載器ClassLoader getTempClassLoader();/*** Set whether to cache bean metadata such as given bean definitions* (in merged fashion) and resolved bean classes. Default is on.* <p>Turn this flag off to enable hot-refreshing of bean definition objects* and in particular bean classes. If this flag is off, any creation of a bean* instance will re-query the bean class loader for newly resolved classes.*/// 是否需要緩存bean metadata,比如bean difinition 和 解析好的classes.默認開啟緩存/** 設置、是否緩存元數據,如果false,那么每次請求實例,都會從類加載器重新加載(熱加載)*/void setCacheBeanMetadata(boolean cacheBeanMetadata);/*** Return whether to cache bean metadata such as given bean definitions* (in merged fashion) and resolved bean classes.*/// 是否需要緩存bean metadata,比如bean difinition 和 解析好的classes.默認開啟緩存// 是否緩存元數據boolean isCacheBeanMetadata();/*** Specify the resolution strategy for expressions in bean definition values.* <p>There is no expression support active in a BeanFactory by default.* An ApplicationContext will typically set a standard expression strategy* here, supporting "#{...}" expressions in a Unified EL compatible style.* @since 3.0*/// 定義用于解析bean definition的表達式解析器/** Bean表達式分解器*/void setBeanExpressionResolver(BeanExpressionResolver resolver);/*** Return the resolution strategy for expressions in bean definition values.* @since 3.0*/// 定義用于解析bean definition的表達式解析器BeanExpressionResolver getBeanExpressionResolver();/*** Specify a Spring 3.0 ConversionService to use for converting* property values, as an alternative to JavaBeans PropertyEditors.* @since 3.0*/// 類型轉化器/** 設置、返回一個轉換服務*/void setConversionService(ConversionService conversionService);/*** Return the associated ConversionService, if any.* @since 3.0*/// 類型轉化器ConversionService getConversionService();/*** Add a PropertyEditorRegistrar to be applied to all bean creation processes.* <p>Such a registrar creates new PropertyEditor instances and registers them* on the given registry, fresh for each bean creation attempt. This avoids* the need for synchronization on custom editors; hence, it is generally* preferable to use this method instead of {@link #registerCustomEditor}.* @param registrar the PropertyEditorRegistrar to register*/// 屬性編輯器/** 設置屬性編輯登記員...*/void addPropertyEditorRegistrar(PropertyEditorRegistrar registrar);/*** Register the given custom property editor for all properties of the* given type. To be invoked during factory configuration.* <p>Note that this method will register a shared custom editor instance;* access to that instance will be synchronized for thread-safety. It is* generally preferable to use {@link #addPropertyEditorRegistrar} instead* of this method, to avoid for the need for synchronization on custom editors.* @param requiredType type of the property* @param propertyEditorClass the {@link PropertyEditor} class to register*/// 屬性編輯器/** 注冊常用屬性編輯器*/void registerCustomEditor(Class<?> requiredType, Class<? extends PropertyEditor> propertyEditorClass);/*** Initialize the given PropertyEditorRegistry with the custom editors* that have been registered with this BeanFactory.* @param registry the PropertyEditorRegistry to initialize*/// 屬性編輯器/** 用工廠中注冊的通用的編輯器初始化指定的屬性編輯注冊器*/void copyRegisteredEditorsTo(PropertyEditorRegistry registry);/*** Set a custom type converter that this BeanFactory should use for converting* bean property values, constructor argument values, etc.* <p>This will override the default PropertyEditor mechanism and hence make* any custom editors or custom editor registrars irrelevant.* @see #addPropertyEditorRegistrar* @see #registerCustomEditor* @since 2.5*/// BeanFactory用來轉換bean屬性值或者參數值的自定義轉換器/** 設置、得到一個類型轉換器*/void setTypeConverter(TypeConverter typeConverter);/*** Obtain a type converter as used by this BeanFactory. This may be a fresh* instance for each call, since TypeConverters are usually <i>not</i> thread-safe.* <p>If the default PropertyEditor mechanism is active, the returned* TypeConverter will be aware of all custom editors that have been registered.* @since 2.5*/// BeanFactory用來轉換bean屬性值或者參數值的自定義轉換器TypeConverter getTypeConverter();/*** Add a String resolver for embedded values such as annotation attributes.* @param valueResolver the String resolver to apply to embedded values* @since 3.0*/// string值解析器(想起mvc中的ArgumentResolver了)/** 增加一個嵌入式的StringValueResolver*/void addEmbeddedValueResolver(StringValueResolver valueResolver);/*** Determine whether an embedded value resolver has been registered with this* bean factory, to be applied through {@link #resolveEmbeddedValue(String)}.* @since 4.3*/boolean hasEmbeddedValueResolver();/*** Resolve the given embedded value, e.g. an annotation attribute.* @param value the value to resolve* @return the resolved value (may be the original value as-is)* @since 3.0*/// string值解析器(想起mvc中的ArgumentResolver了)//分解指定的嵌入式的值String resolveEmbeddedValue(String value);/*** Add a new BeanPostProcessor that will get applied to beans created* by this factory. To be invoked during factory configuration.* <p>Note: Post-processors submitted here will be applied in the order of* registration; any ordering semantics expressed through implementing the* {@link org.springframework.core.Ordered} interface will be ignored. Note* that autodetected post-processors (e.g. as beans in an ApplicationContext)* will always be applied after programmatically registered ones.* @param beanPostProcessor the post-processor to register*/// BeanPostProcessor用于增強bean初始化功能//設置一個Bean后處理器void addBeanPostProcessor(BeanPostProcessor beanPostProcessor);/*** Return the current number of registered BeanPostProcessors, if any.*///返回Bean后處理器的數量int getBeanPostProcessorCount();/*** Register the given scope, backed by the given Scope implementation.* @param scopeName the scope identifier* @param scope the backing Scope implementation*/// 作用域定義//注冊范圍void registerScope(String scopeName, Scope scope);/*** Return the names of all currently registered scopes.* <p>This will only return the names of explicitly registered scopes.* Built-in scopes such as "singleton" and "prototype" won't be exposed.* @return the array of scope names, or an empty array if none* @see #registerScope*/// 作用域定義//返回注冊的范圍名String[] getRegisteredScopeNames();/*** Return the Scope implementation for the given scope name, if any.* <p>This will only return explicitly registered scopes.* Built-in scopes such as "singleton" and "prototype" won't be exposed.* @param scopeName the name of the scope* @return the registered Scope implementation, or {@code null} if none* @see #registerScope*/// 作用域定義//返回指定的范圍Scope getRegisteredScope(String scopeName);/*** Provides a security access control context relevant to this factory.* @return the applicable AccessControlContext (never {@code null})* @since 3.0*/// 訪問權限控制//返回本工廠的一個安全訪問上下文AccessControlContext getAccessControlContext();/*** Copy all relevant configuration from the given other factory.* <p>Should include all standard configuration settings as well as* BeanPostProcessors, Scopes, and factory-specific internal settings.* Should not include any metadata of actual bean definitions,* such as BeanDefinition objects and bean name aliases.* @param otherFactory the other BeanFactory to copy from*/// 合并其他ConfigurableBeanFactory的配置,包括上面說到的BeanPostProcessor,作用域等//從其他的工廠復制相關的所有配置void copyConfigurationFrom(ConfigurableBeanFactory otherFactory);/*** Given a bean name, create an alias. We typically use this method to* support names that are illegal within XML ids (used for bean names).* <p>Typically invoked during factory configuration, but can also be* used for runtime registration of aliases. Therefore, a factory* implementation should synchronize alias access.* @param beanName the canonical name of the target bean* @param alias the alias to be registered for the bean* @throws BeanDefinitionStoreException if the alias is already in use*/// bean定義處理// 注冊別名/** 給指定的Bean注冊別名*/void registerAlias(String beanName, String alias) throws BeanDefinitionStoreException;/*** Resolve all alias target names and aliases registered in this* factory, applying the given StringValueResolver to them.* <p>The value resolver may for example resolve placeholders* in target bean names and even in alias names.* @param valueResolver the StringValueResolver to apply* @since 2.5*/// bean定義處理//根據指定的StringValueResolver移除所有的別名void resolveAliases(StringValueResolver valueResolver);/*** Return a merged BeanDefinition for the given bean name,* merging a child bean definition with its parent if necessary.* Considers bean definitions in ancestor factories as well.* @param beanName the name of the bean to retrieve the merged definition for* @return a (potentially merged) BeanDefinition for the given bean* @throws NoSuchBeanDefinitionException if there is no bean definition with the given name* @since 2.5*/// bean定義處理// 合并bean定義,包括父容器的/** 返回指定Bean合并后的Bean定義*/BeanDefinition getMergedBeanDefinition(String beanName) throws NoSuchBeanDefinitionException;/*** Determine whether the bean with the given name is a FactoryBean.* @param name the name of the bean to check* @return whether the bean is a FactoryBean* ({@code false} means the bean exists but is not a FactoryBean)* @throws NoSuchBeanDefinitionException if there is no bean with the given name* @since 2.5*/// bean定義處理// 是否是FactoryBean類型//判斷指定Bean是否為一個工廠Beanboolean isFactoryBean(String name) throws NoSuchBeanDefinitionException;/*** Explicitly control the current in-creation status of the specified bean.* For container-internal use only.* @param beanName the name of the bean* @param inCreation whether the bean is currently in creation* @since 3.1*/// bean創建狀態控制.在解決循環依賴時有使用//設置一個Bean是否正在創建void setCurrentlyInCreation(String beanName, boolean inCreation);/*** Determine whether the specified bean is currently in creation.* @param beanName the name of the bean* @return whether the bean is currently in creation* @since 2.5*/// bean創建狀態控制.在解決循環依賴時有使用//返回指定Bean是否已經成功創建boolean isCurrentlyInCreation(String beanName);/*** Register a dependent bean for the given bean,* to be destroyed before the given bean is destroyed.* @param beanName the name of the bean* @param dependentBeanName the name of the dependent bean* @since 2.5*/// 處理bean依賴問題//注冊一個依賴于指定bean的Beanvoid registerDependentBean(String beanName, String dependentBeanName);/*** Return the names of all beans which depend on the specified bean, if any.* @param beanName the name of the bean* @return the array of dependent bean names, or an empty array if none* @since 2.5*/// 處理bean依賴問題//返回依賴于指定Bean的所欲Bean名String[] getDependentBeans(String beanName);/*** Return the names of all beans that the specified bean depends on, if any.* @param beanName the name of the bean* @return the array of names of beans which the bean depends on,* or an empty array if none* @since 2.5*/// 處理bean依賴問題//返回指定Bean依賴的所有Bean名String[] getDependenciesForBean(String beanName);/*** Destroy the given bean instance (usually a prototype instance* obtained from this factory) according to its bean definition.* <p>Any exception that arises during destruction should be caught* and logged instead of propagated to the caller of this method.* @param beanName the name of the bean definition* @param beanInstance the bean instance to destroy*/// bean生命周期管理-- 銷毀bean//銷毀指定的Beanvoid destroyBean(String beanName, Object beanInstance);/*** Destroy the specified scoped bean in the current target scope, if any.* <p>Any exception that arises during destruction should be caught* and logged instead of propagated to the caller of this method.* @param beanName the name of the scoped bean*/// bean生命周期管理-- 銷毀bean//銷毀指定的范圍Beanvoid destroyScopedBean(String beanName);/*** Destroy all singleton beans in this factory, including inner beans that have* been registered as disposable. To be called on shutdown of a factory.* <p>Any exception that arises during destruction should be caught* and logged instead of propagated to the caller of this method.*/// bean生命周期管理-- 銷毀bean//銷毀所有的單例類void destroySingletons();}

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/249519.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/249519.shtml
英文地址,請注明出處:http://en.pswp.cn/news/249519.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Xlua文件在熱更新中調用方法

Xlua文件在熱更新中調用方法 public class news : MonoBehaviour { LuaEnv luaEnv;//定義Lua初始變量 void Awake() { luaEnv new LuaEnv();//new開辟空間 luaEnv.AddLoader(myload);//調用方法地址、返回字節 luaEnv.DoString("requirefish");//更新文件 } void O…

springboot 使用的配置

1&#xff0c;控制臺打印sql logging:level:com.sdyy.test.mapper: debug 2&#xff0c;開啟駝峰命名 mybatis.configuration.map-underscore-to-camel-casetrue 轉載于:https://www.cnblogs.com/xiaohu1218/p/10477318.html

AutowireCapableBeanFactory接口

AutowireCapableBeanFactory在BeanFactory基礎上實現了對存在實例的管理.可以使用這個接口集成其它框架,捆綁并填充并不由Spring管理生命周期并已存在的實例.像集成WebWork的Actions 和Tapestry Page就很實用. 一般應用開發者不會使用這個接口,所以像ApplicationContext這樣的…

外觀模式

一、什么是外觀模式   有些人可能炒過股票&#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