new SpringApplication()
??記錄primarySources
??判定webApplicationType(具體流程可參考相關(guān)流程圖)
規(guī)則:
有引入spring MVC框架或者jersey框架則返回WebApplicationType.SERVLET口糕。
存在Org.springframework.web.reactive.DispatcherHandler類則返回WebApplicationType.REACTIVE鳄炉。
不存在javax.servlet.Servlet或org.springframework.web.context.ConfigurableWebApplicationContext則返回NONE
其他則默認(rèn)SERVLET
??設(shè)置initializers
SpringFactoriesLoader負(fù)責(zé)加載spring.factories配置锄蹂;該處將返回org.springframework.context.ApplicationContextInitializer的所有bean實例
??設(shè)置ApplicationListener相關(guān)的所有l(wèi)istener
spring.factories中設(shè)置的org.springframework.context.ApplicationListener的所有bean實例
獲取SpringApplicationRunListeners相關(guān)的listener
spring.factories中設(shè)置的org.springframework.boot.SpringApplicationRunListener相關(guān)的所有bean實例。其中有一個EventPublishingRunListener類型的bean,在初始化時,會將上一步的ApplicationListener類型的listerners全部注冊起來。
prepareEnvironment
springboot在此之前將從bean工廠中獲取SpringApplicationRunListner類型的bean驱敲,然后封裝程SpringApplicationRunListners對象傳入此方法。而該方法主要負(fù)責(zé)遍歷調(diào)用各個監(jiān)聽器的environmentPrepared方法
configureIngoreBeanInfo
設(shè)置spring.beaninfo.ignore煤伟,用途暫未知
createApplicationContext
如果WebApplicationType是SERVLET則使用org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext
如果是REACTIVE癌佩,則使用org.springframework.boot.web.servlet.context.AnnotationConfigReactiveWebServerApplicationContext
prepareContext
給context設(shè)置environment ....
將context傳給所有initializer初始化一遍
將context傳給所有應(yīng)用監(jiān)聽器prepareContext一遍
創(chuàng)建啟動類對應(yīng)的bean
遍歷各監(jiān)聽器的contextLoaded方法
refreshContext
AnnotationConfigReactiveWebServerApplicationContext.refresh
prepareRefresh()
prepareBeanFactory(beanFactory):
postProcessBeanFactory(beanFactory)
invokeBeanFactoryPostProcessors(beanFactory) 讀出入口應(yīng)用所在包下的所有注解bean類木缝,初始化bean
registerBeanPostProcessors(beanFactory)
onRefresh()-->創(chuàng)建webserver便锨。并調(diào)用WebServerFactoryCustomizer相關(guān)bean(由EmbededWebServerFactoryCustomizerAutoConfigureation等配置類創(chuàng)建)進(jìn)行個性化設(shè)置。
registerListeners()
finishBeanFactoryInitialization(beanFactory)-->觸發(fā)注冊用戶自定義的監(jiān)聽器(ApplicationListenerDetector.postProcessAfterInitialization(bean, beanName))
finishRefresh()