我已經很精簡了,兩篇(Spring Boot啟動過程(一)、spring Boot啟動過程(二))依然沒寫完,接著來。
refreshContext之后的方法是afterRefresh,這名字起的真...好。afterRefresh方法內只調用了callRunners一個方法,這個方法從上下文中獲取了所有的ApplicationRunner和CommandLineRunner接口的實現類,并執行這些實現類的run方法。例如Spring Batch的JobLauncherCommandLineRunner:
1
2
3
4
5
|
@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)實際上是在exception為null的情況下發布了ApplicationReadyEvent事件。
啟動至此就差不多了,于是停止stopWatch.stop(),然后把時間打到日志里:Started Application in ***.462 seconds (JVM running for ***.977),然后感受下這記完就扔的氣勢:
1
2
3
4
|
if ( this .logStartupInfo) { new StartupInfoLogger( this .mainApplicationClass) .logStarted(getApplicationLog(), stopWatch); } |
最后返回個context,run方法就到此結束了。
==========================================================
咱最近用的github:https://github.com/saaavsaaa
以上所述是小編給大家介紹的Spring Boot啟動過程全面解析(三),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對服務器之家網站的支持!
原文鏈接:http://www.cnblogs.com/saaav/p/6322844.html