欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Spring Boot启动过程全面解析(三)

程序员文章站 2024-02-29 14:24:22
我已经很精简了,两篇(spring boot启动过程(一)、spring boot启动过程(二))依然没写完,接着来。   refreshcontext之后的方法是aft...

我已经很精简了,两篇(spring boot启动过程(一)spring boot启动过程(二))依然没写完,接着来。

  refreshcontext之后的方法是afterrefresh,这名字起的真...好。afterrefresh方法内只调用了callrunners一个方法,这个方法从上下文中获取了所有的applicationrunner和commandlinerunner接口的实现类,并执行这些实现类的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)实际上是在exception为null的情况下发布了applicationreadyevent事件。

  启动至此就差不多了,于是停止stopwatch.stop(),然后把时间打到日志里:started application in ***.462 seconds (jvm running for ***.977),然后感受下这记完就扔的气势:         

 if (this.logstartupinfo) {
    new startupinfologger(this.mainapplicationclass)
      .logstarted(getapplicationlog(), stopwatch);
   }

   最后返回个context,run方法就到此结束了。

==========================================================

咱最近用的github:

以上所述是小编给大家介绍的spring boot启动过程全面解析(三),希望对大家有所帮助