天天看點

SpringBoot源碼----真正的bean工廠DefaultListableBeanFactory

類的注解和翻譯:

/**
 * Spring's default implementation of the {@link ConfigurableListableBeanFactory}
 * and {@link BeanDefinitionRegistry} interfaces: a full-fledged bean factory
 * based on bean definition metadata, extensible through post-processors.
 *
 * <p>Typical usage is registering all bean definitions first (possibly read
 * from a bean definition file), before accessing beans. Bean lookup by name
 * is therefore an inexpensive operation in a local bean definition table,
 * operating on pre-resolved bean definition metadata objects.
 *
 * <p>Note that readers for specific bean definition formats are typically
 * implemented separately rather than as bean factory subclasses:
 * see for example {@link PropertiesBeanDefinitionReader} and
 * {@link org.springframework.beans.factory.xml.XmlBeanDefinitionReader}.
 *
 * <p>For an alternative implementation of the
 * {@link org.springframework.beans.factory.ListableBeanFactory} interface,
 * have a look at {@link StaticListableBeanFactory}, which manages existing
 * bean instances rather than creating new ones based on bean definitions.
 */
Spring的ConfigurableListableBeanFactory和BeanDefinitionRegistry接口的預設實作:基于bean定義中繼資料的成熟bean工廠,可通過後處理器進行擴充。
典型的用法是在通路bean之前先注冊所有bean定義(可能是從bean定義檔案中讀取)。是以,按名稱查找Bean是在本地Bean定義表中進行的廉價操作,它對預解析的Bean定義中繼資料對象進行操作。
注意,特定bean定義格式的閱讀器通常是單獨實作的,而不是作為bean工廠的子類實作的:例如,參見PropertiesBeanDefinitionReader和org.springframework.beans.factory.xml.XmlBeanDefinitionReader。
對于org.springframework.beans.factory.ListableBeanFactory接口的替代實作,請看一下StaticListableBeanFactory,它管理現有的bean執行個體,而不是根據bean定義建立新的bean執行個體。
           

類圖:

SpringBoot源碼----真正的bean工廠DefaultListableBeanFactory