我已經(jīng)很精簡了,兩篇(Spring Boot啟動過程(一)、spring Boot啟動過程(二))依然沒寫完,接著來。
refreshContext之后的方法是afterRefresh,這名字起的真...好。afterRefresh方法內(nèi)只調(diào)用了callRunners一個方法,這個方法從上下文中獲取了所有的ApplicationRunner和CommandLineRunner接口的實(shí)現(xiàn)類,并執(zhí)行這些實(shí)現(xiàn)類的run方法。例如Spring Batch的JobLauncherCommandLineRunner:
@Override public void run(String... args) throws JobExecutionException { logger.info("Running default command line with: " + Arrays.asList(args)); launchJobFromProperties(StringUtils.splitArrayElementsIntoProperties(args, "=")); }listeners.finished(context, null)實(shí)際上是在exception為null的情況下發(fā)布了ApplicationReadyEvent事件。
啟動至此就差不多了,于是停止stopWatch.stop(),然后把時間打到日志里:Started Application in ***.462 seconds (JVM running for ***.977),然后感受下這記完就扔的氣勢:
if (this.logStartupInfo) { new StartupInfoLogger(this.mainApplicationClass) .logStarted(getApplicationLog(), stopWatch); }最后返回個context,run方法就到此結(jié)束了。
==========================================================
咱最近用的github:https://github.com/saaavsaaa
以上所述是小編給大家介紹的Spring Boot啟動過程全面解析(三),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對武林網(wǎng)網(wǎng)站的支持!
新聞熱點(diǎn)
疑難解答
圖片精選