码迷,mamicode.com
首页 > 编程语言 > 详细

Spring Boot启动过程(三)

时间:2017-01-20 17:21:11      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:started   实现   ini   split   main   ref   com   void   color   

  我已经很精简了,两篇(Spring Boot启动过程(一)pring 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:https://github.com/saaavsaaa

微信公众号:

                      技术分享

Spring Boot启动过程(三)

标签:started   实现   ini   split   main   ref   com   void   color   

原文地址:http://www.cnblogs.com/saaav/p/6322844.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!