代碼:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<beans>
<bean class="com.ant.demo.Entity" id="entity"></bean>
<bean class="com.ant.demo.MyBeanFactoryPorstProcessor" id="myBeanFactoryPorstProcessor"></bean>
<bean class="com.ant.demo.MyBeanPostProcessor" id="myBeanPostProcessor"></bean>
</beans>
</beans>
package com.ant.demo;
import org.springframework.stereotype.Component;
@Component
public class Entity {
private String id;
private String name;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
package com.ant.demo;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
public class MyBeanFactoryPorstProcessor implements BeanFactoryPostProcessor {
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
System.out.println(beanFactory);
System.out.println("已經啓動");
}
}
package com.ant.demo;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
public class MyBeanPostProcessor implements BeanPostProcessor {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
System.out.println("before---------");
return beanName+":"+bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
System.out.println("after---------");
return beanName+":"+bean;
}
}
public static void main(String[] args) {
ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
Entity bean = classPathXmlApplicationContext.getBean(Entity.class);
System.err.println(bean);
}
springContext執行流程分析: >ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext("applicationContext.xml"); 創建一個ApplicationContext # refresh()(org.springframework.context.ConfigurableApplicationContext.refresh)的doc文檔: # Load or refresh the persistent representation of the configuration, - 翻譯:加載或者刷新配置(configuration) # which might an XML file, properties file, or relational database schema. - 翻譯:加載或者刷新的配置文件有可能是XML文件、properties文件或者關係型數據庫 # As this is a startup method, it should destroy already created singletons - 翻譯:作爲一個啓動方法,它應該銷燬已經創建的單例實例 # if it fails, to avoid dangling resources. - 翻譯:如果銷燬失敗,避免無用資源 # In other words, after invocation of that method, either all or no singletons at all should be instantiated. - 翻譯:總得來說,調用本方法之後,要麼全部被實例化,要麼一個都不會被實例化 >org.springframework.context.support.AbstractApplicationContext.refresh # doc文檔: # Prepare this context for refreshing, - 翻譯:爲更新操作預先準備上下文環境 # setting its startup date and active flag as well as performing any initialization of property sources. - 翻譯:設置啓動日誌和有效標識以及執行其他的初始化屬性 >org.springframework.context.support.AbstractApplicationContext.prepareRefresh # doc文檔: # Tell the subclass to refresh the internal bean factory. - 翻譯:通知子類更新其內部bean Factory # return the fresh BeanFactory instance - 返回一個全新的BeanFactory >org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory # doc文檔: # Configure the factory's standard context characteristics, - 翻譯: # such as the context's ClassLoader and post-processors. - 翻譯:配置BeanFactory標準上下文信息,例如上下文的Classloader和post-processors等 >org.springframework.context.support.AbstractApplicationContext.prepareBeanFactory # doc文檔: # Modify the application context's internal bean factory after its standard initialization. - 翻譯:在初始化完BeanFactory的標準上下文信息後,修改上下文的內部beanFactory # All bean definitions will have been loaded,but no beans will have been instantiated yet. - 翻譯:所有的bean definitions將會被加載,但是到目前爲止沒有bean被實例化 # This allows for registering special BeanPostProcessors etc in certain ApplicationContext implementations. - 翻譯:這允許在特殊的ApplicationContext實現中註冊特殊的BeanPostProcessors等操作 >org.springframework.context.support.AbstractApplicationContext.postProcessBeanFactory # doc文檔: # Instantiate and invoke all registered BeanFactoryPostProcessor beans,- 翻譯:實例化所有已經註冊的BeanFactoryPostProcessor,並且調用其postProcessBeanFactory()方法, # respecting explicit order if given. - 翻譯如果註冊的postProcessBeanFactory有Order(org.springframework.core.annotation.Order)註解,則會嚴格按照Order定義的順序來執行 >org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors # doc文檔: # Instantiate and register all BeanPostProcessor beans, - 翻譯:實例化並註冊所有的BeanPostProcessor, # respecting explicit order if given. - 翻譯:如果BeanPostProcessor有Order(org.springframework.core.annotation.Order)註解,則會嚴格按照定義的順序執行 >org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors # doc文檔: # Initialize the MessageSource.Use parent's if none defined in this context. - 翻譯:初始化MessageSource,如果沒有定義就會默認使用父類的 >org.springframework.context.support.AbstractApplicationContext.initMessageSource # doc文檔: # Initialize the ApplicationEventMulticaster. - 翻譯:初始化ApplicationEventMulticaster # Uses SimpleApplicationEventMulticaster if none defined in the context. - 翻譯:如果沒有定義則會使用 SimpleApplicationEventMulticaster >org.springframework.context.support.AbstractApplicationContext.initApplicationEventMulticaster # doc文檔: # Template method which can be overridden to add context-specific refresh work. - 翻譯:可以被重寫的模板方法,在refresh增加一些特殊操作 # Called on initialization of special beans, before instantiation of singletons. - 翻譯:在實例化單例之前,初始化特殊的bean的時候被調用 # This implementation is empty. - 翻譯:他的實現類是空 >org.springframework.context.support.AbstractApplicationContext.onRefresh # doc文檔: # Add beans that implement ApplicationListener as listeners. - 翻譯:將實現了ApplicationListener的bean添加爲監聽器 # Doesn't affect other listeners, which can be added without being beans. - 翻譯:可以在不存在bean的時候添加,不會影響其他監聽器 >org.springframework.context.support.AbstractApplicationContext.registerListeners # doc文檔: # Finish the initialization of this context's bean factory,initializing all remaining singleton beans. - 翻譯:完成上下文的beanFactory初始化,初始化剩餘的單例bean >org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization # doc文檔: #Finish the refresh of this context, invoking the LifecycleProcessor's onRefresh() method and publishing the {@link org.springframework.context.event.ContextRefreshedEvent}. # - 翻譯:完成上下文的更新,調用LifecycleProcessor的onRefresh()方法,發佈org.springframework.context.event.ContextRefreshedEvent >org.springframework.context.support.AbstractApplicationContext.finishRefresh 1.1 org.springframework.context.support.AbstractApplicationContext.prepareRefresh() # doc文檔: # Prepare this context for refreshing, - 翻譯:爲更新操作預先準備上下文環境 # setting its startup date and active flag as well as performing any initialization of property sources. - 翻譯:設置啓動日誌和有效標識以及執行其他的初始化屬性 >org.springframework.context.support.AbstractApplicationContext.prepareRefresh 1.2 org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory() # doc文檔: # Tell the subclass to refresh the internal bean factory. - 翻譯:通知子類更新其內部bean Factory # return the fresh BeanFactory instance - 返回一個全新的BeanFactory >org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory # doc文檔: # This implementation performs an actual refresh of this context's underlying bean factory, - 翻譯:這個實現(指AbstractRefreshableApplicationContext)執行真正的beanFactory最底層的更新操作。 # 翻譯:停止之前存在bean factory,爲上下文的聲明週期初始化一個新的bean factory # shutting down the previous bean factory (if any) and initializing a fresh bean factory for the next phase of the context's lifecycle. >org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory >org.springframework.context.support.AbstractRefreshableApplicationContext.createBeanFactory,創建一個BeanFactory實例,實際類型是org.springframework.beans.factory.support.DefaultListableBeanFactory >org.springframework.context.support.AbstractRefreshableApplicationContext.customizeBeanFactory 對創建的BeanFactory做一些定製化配置 # doc文檔: # Loads the bean definitions via an XmlBeanDefinitionReader. - 翻譯:使用XmlBeanDefinitionReader加載bean definitions >org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions # doc文檔: # Initialize the bean definition reader used for loading the bean definitions of this context. - 翻譯:初始化一個bean definition reader用於加載bean definitions到當前上下文中 # Default implementation is empty. - 翻譯:默認實現爲空 # Can be overridden in subclasses, e.g. for turning off XML validation or using a different XmlBeanDefinitionParser implementation. - 翻譯:可以被子類重寫,例如,爲了關閉XML校驗或使用一個不同的XmlBeanDefinitionParser解析器實現 >org.springframework.context.support.AbstractXmlApplicationContext.initBeanDefinitionReader - 源碼中此處默認xml校驗爲true # doc文檔: # Load the bean definitions with the given XmlBeanDefinitionReader. - 翻譯:使用給定的XmlBeanDefinitionReader加載bean definitions # The lifecycle of the bean factory is handled by the {@link #refreshBeanFactory} method; - 翻譯:bean factory的生命週期被refreshBeanFactory()方法處理 # hence this method is just supposed to load and/or register bean definitions. - 翻譯:因此這個方法只是用來加載和/或註冊bean definitions >org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions >org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions - 此處開始根據xml的location(本案例中是applicationContext.xml)進行加載beanDefinition # doc文檔 # Load bean definitions from the specified resource location. - 翻譯:從指定的resource location中加載bean definitions # The location can also be a location pattern, provided that the ResourceLoader of this bean definition reader is a ResourcePatternResolver. - 翻譯:如果bean definition的ResourceLoader是ResourcePatternResolver,那麼location可以是一個location表達式(pattern) >org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions >org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions - Load bean definitions from the specified XML file. 使用XmlBeanDefinitionReader從特殊的xml文件中加載BeanDefinition >org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions - Actually load bean definitions from the specified XML file.真實執行從XML文件中加載BeanDefinition的方法 >org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions >org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions # doc文檔 # Register each bean definition within the given root {@code <beans/>} element. - 翻譯:從 <beans/>節點開始,將註冊每一個beanDefinition >org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions # Parse the elements at the root level in the document:"import", "alias", "bean". - 翻譯:從文檔的根節點解析"import", "alias", "bean"節點 >org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions >org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseDefaultElement - 此處我們可以看到已經開始解析<beans>標籤 # 從<beans>標籤開始解析,解析到<bean>標籤後,來到processBeanDefinition方法 # doc文檔: # Process the given bean element, parsing the bean definition and registering it with the registry. # 翻譯:處理bean元素,解析並且將其註冊 >org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.processBeanDefinition # Register the given bean definition with the given bean factory. 將給定的beanDefinition註冊到給定的bean factory中(此處是DefaultListableBeanFactory) >org.springframework.beans.factory.support.BeanDefinitionReaderUtils.registerBeanDefinition # 此處來到我們的BeanFactory:DefaultListableBeanFactory,對bean進行註冊 # 最終bean是註冊到org.springframework.beans.factory.support.DefaultListableBeanFactory.beanDefinitionMap中 # beanDefinitionMap是DefaultListableBeanFactory的一個屬性,原型是ConcurrentHashMap<beanName,BeanDefinition> >org.springframework.beans.factory.support.DefaultListableBeanFactory.registerBeanDefinition >org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory - 獲取上方流程中已經加載完成BeanDefinition的BeanFactory,實際上也就是DefaultListableBeanFactory 1.3 org.springframework.context.support.AbstractApplicationContext.prepareBeanFactory() # doc文檔: # Configure the factory's standard context characteristics, - 翻譯: # such as the context's ClassLoader and post-processors. - 翻譯:配置BeanFactory標準上下文信息,例如上下文的Classloader和post-processors等 >org.springframework.context.support.AbstractApplicationContext.prepareBeanFactory 配置BeanFactory一些信息 1.4 org.springframework.context.support.AbstractApplicationContext.postProcessBeanFactory() # doc文檔: # Modify the application context's internal bean factory after its standard initialization. - 翻譯:在初始化完BeanFactory的標準上下文信息後,修改上下文的內部beanFactory # All bean definitions will have been loaded,but no beans will have been instantiated yet. - 翻譯:所有的bean definitions將會被加載,但是到目前爲止沒有bean被實例化 # This allows for registering special BeanPostProcessors etc in certain ApplicationContext implementations. - 翻譯:這允許在特殊的ApplicationContext實現中註冊特殊的BeanPostProcessors等操作 >org.springframework.context.support.AbstractApplicationContext.postProcessBeanFactory 1.5 org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors() # doc文檔: # Instantiate and invoke all registered BeanFactoryPostProcessor beans,- 翻譯:實例化所有已經註冊的BeanFactoryPostProcessor,並且調用其postProcessBeanFactory()方法, # respecting explicit order if given. - 翻譯如果註冊的postProcessBeanFactory有Order(org.springframework.core.annotation.Order)註解,則會嚴格按照Order定義的順序來執行 >org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors # org.springframework.beans.factory.config.BeanFactoryPostProcessor的doc文檔 # Factory hook that allows for custom modification of an application context's bean definitions, - 翻譯:允許用戶自定義修改application context中的bean definitions的工廠鉤子 # adapting the bean property values of the context's underlying bean factory. - 翻譯:調整上下文的基礎bean工廠的bean屬性值 # Useful for custom config files targeted at system administrators that override bean properties configured in the application context. - 翻譯:對於需要在應用上下文中通過子弟應以配置文件覆蓋bean的屬性的系統管理員而言是非常有用的 # See {@link PropertyResourceConfigurer} and its concrete implementations for out-of-the-box solutions that address such configuration needs. - 翻譯:查看PropertyResourceConfigurer,它針對解決此類配置需求的開箱即用解決方案的具體實現 # A {@code BeanFactoryPostProcessor} may interact with and modify bean definitions,but never bean instances. - 翻譯:BeanFactoryPostProcessor可能會影響或修改bean definitions,但是永遠不會影響bean的實例 # Doing so may cause premature bean instantiation, violating the container and causing unintended side-effects. - 翻譯:這樣做可能會導致過早實例化bean,破壞容器並導致意外的副作用 # If bean instance interaction is required, consider implementing {@link BeanPostProcessor} instead. - 如果需要和bean實例進行交互,可以考慮實現BeanPostProcessor接口,而不是實現BeanFactoryPostProcessor接口 >org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors 在此處我們可以看到spring會調用所有的BeanFactoryPostProcessor的postProcessBeanDefinitionRegistry方法 >org.springframework.beans.factory.support.AbstractBeanFactory.getBean spring 在此處開始實例化我們自定義的BeanFactoryPostProcessor # doc文檔: # Return an instance, which may be shared or independent, of the specified bean. - 翻譯:返回一個指定名稱的bean的實例,該實例是可以被共享或者獨立 >org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean 此處開始具體操作 # 註釋:Eagerly check singleton cache for manually registered singletons.檢查單例緩存中手動註冊的單例對象 >org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton 默認獲取單例模式的bean # doc文檔: # Return the (raw) singleton object registered under the given name. - 翻譯:返回註冊到給定名稱下注冊的bean # Checks already instantiated singletons and also allows for an early reference to a currently created singleton (resolving a circular reference). - 翻譯:檢查已經創建的單例對象,也允許一個早期引用指向當前創建的單例對象(解決循環依賴問題) >org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton # doc文檔 # Mark the specified bean as already created (or about to be created). - 翻譯:標記已經被創建的特殊的bean # This allows the bean factory to optimize its caching for repeated creation of the specified bean. - 這允許bean factory對於重複創建的特殊的bean優化他的緩存 >org.springframework.beans.factory.support.AbstractBeanFactory.markBeanAsCreated # doc註釋: # Central method of this class: creates a bean instance,populates the bean instance, applies post-processors, etc.這個類(AbstractAutowireCapableBeanFactory)的核心方法,創建bean的實例,填充bean的實例,適用於後置處理器等等 >org.springframework.beans.factory.support.AbstractBeanFactory.createBean # doc文檔: # Actually create the specified bean. - 翻譯:真實的創建一個指定的bean # Pre-creation processing has already happened at this point, e.g.checking {@code postProcessBeforeInstantiation} callbacks. - 翻譯:在此之前已經進行了預處理邏輯,例如:檢查postProcessBeforeInstantiation回調 # Differentiates between default bean instantiation, use of a , use of a factory method, and autowiring a constructor.- 翻譯:與默認的bean的實例化的區別是,使用factory method,自動注入一個構造函數 >org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean #doc文檔: # Create a new instance for the specified bean, using an appropriate instantiation strategy:factory method, constructor autowiring, or simple instantiation. # 翻譯:爲指定的bean創建實例,使用支持的實例化策略,包含工廠方法,構造方法注入或者簡單的實例化 >org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance - 在此處我們可以看到實際上返回的是一個org.springframework.beans.BeanWrapper對象,支持工廠方法等一系列策略創建bean實例 # doc文檔: # Instantiate the given bean using its default constructor.使用默認的構造方法實例化一個bean >org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean >org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getInstantiationStrategy - 在這裏返回的實例化策略我們可以看到這裏使用的是cglib->instantiationStrategy = new CglibSubclassingInstantiationStrategy(); >org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate >org.springframework.beans.BeanWrapperImpl - 將實例化的對象封裝到BeanWrapper中 >org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors - 在此處開始調用我們自定義的的BeanFactoryPosetProcessor的postProcessBeanFactory方法 1.6 org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors() # doc文檔: # Instantiate and register all BeanPostProcessor beans, - 翻譯:實例化並註冊所有的BeanPostProcessor, # respecting explicit order if given. - 翻譯:如果BeanPostProcessor有Order(org.springframework.core.annotation.Order)註解,則會嚴格按照定義的順序執行 >org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors # doc文檔: # Instantiate and register all BeanPostProcessor beans,respecting explicit order if given. - 翻譯:實例化並註冊所有的BeanPostProcessor,如果定義了順序,則嚴格按照給定的順序執行 >org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors >org.springframework.beans.factory.BeanFactory.getBean - 開始進入創建bean的流程,該流程實際上上方創建BeanFactoryPostProcessor已經分析過,此處我們簡單再過一遍關鍵代碼 >org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean >org.springframework.beans.factory.support.AbstractBeanFactory.createBean >org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean >org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance 此處實際上創建了bean之後,把bean包裝到wapper中,上方已經講過 >org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean 此處開始實例化bean >org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate 此處開始使用實際的實例化策略開始實例化bean >org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton >org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors >org.springframework.beans.factory.support.AbstractBeanFactory.addBeanPostProcessor - 在此處我們可以看到所有的beanPostProcessor實際上是存放到AbstractBeanFactory中的beanPostProcessors = new CopyOnWriteArrayList<>();屬性中 1.7 org.springframework.context.support.AbstractApplicationContext.initMessageSource() # doc文檔: # Initialize the MessageSource.Use parent's if none defined in this context. - 翻譯:初始化MessageSource,如果沒有定義就會默認使用父類的 >org.springframework.context.support.AbstractApplicationContext.initMessageSource 1.8 org.springframework.context.support.AbstractApplicationContext.initApplicationEventMulticaster() # doc文檔: # Initialize the ApplicationEventMulticaster. - 翻譯:初始化ApplicationEventMulticaster # Uses SimpleApplicationEventMulticaster if none defined in the context. - 翻譯:如果沒有定義則會使用 SimpleApplicationEventMulticaster >org.springframework.context.support.AbstractApplicationContext.initApplicationEventMulticaster 1.9 org.springframework.context.support.AbstractApplicationContext.onRefresh() # doc文檔: # Template method which can be overridden to add context-specific refresh work. - 翻譯:可以被重寫的模板方法,在refresh增加一些特殊操作 # Called on initialization of special beans, before instantiation of singletons. - 翻譯:在實例化單例之前,初始化特殊的bean的時候被調用 # This implementation is empty. - 翻譯:他的實現類是空 >org.springframework.context.support.AbstractApplicationContext.onRefresh 2.0 org.springframework.context.support.AbstractApplicationContext.registerListeners() # doc文檔: # Add beans that implement ApplicationListener as listeners. - 翻譯:將實現了ApplicationListener的bean添加爲監聽器 # Doesn't affect other listeners, which can be added without being beans. - 翻譯:可以在不存在bean的時候添加,不會影響其他監聽器 >org.springframework.context.support.AbstractApplicationContext.registerListeners 2.1 org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization() # doc文檔: # Finish the initialization of this context's bean factory,initializing all remaining singleton beans. - 翻譯:完成上下文的beanFactory初始化,初始化剩餘的單例bean >org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization # 註釋:Register a default embedded value resolver if no bean post-processor(such as a PropertyPlaceholderConfigurer bean) registered any before : 如果沒有bean post-processor,則在註冊之前註冊一個內置的 value resolver,例如:PropertyPlaceholderConfigurer # at this point, primarily for resolution in annotation attribute values. : 在此刻,主要用於解析屬性值 >org.springframework.beans.factory.config.ConfigurableBeanFactory.addEmbeddedValueResolver # 註釋:Instantiate all remaining (non-lazy-init) singletons.實例化所有剩餘的不是懶加載的單例bean >org.springframework.beans.factory.config.ConfigurableListableBeanFactory.preInstantiateSingletons # 開始一個個的創建bean,此處邏輯我們上方已經分析過此處就不過多分析 >org.springframework.beans.factory.support.AbstractBeanFactory.getBean >org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean >org.springframework.beans.factory.support.AbstractBeanFactory.createBean >org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean >org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance >org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean 如果沒有特殊的實例化方式,則採用默認的構造函數實例化 >org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton 2.2 org.springframework.context.support.AbstractApplicationContext.finishRefresh() # doc文檔: #Finish the refresh of this context, invoking the LifecycleProcessor's onRefresh() method and publishing the {@link org.springframework.context.event.ContextRefreshedEvent}. # - 翻譯:完成上下文的更新,調用LifecycleProcessor的onRefresh()方法,發佈org.springframework.context.event.ContextRefreshedEvent >org.springframework.context.support.AbstractApplicationContext.finishRefresh
截圖: