springboot启动源码分析5——剩余内容

springboot启动源码分析1——初步初始化

springboot启动源码分析2——run方法分析

springboot启动源码分析3——环境配置

springboot启动源码分析4——刷新容器

springboot启动源码分析5——后续处理内容

Spring Boot启动源码分析6——refresh的invokeBeanFactoryPostProcessors方法详解

springboot启动源码分析7——自动配置

springboot启动源码分析8——aop

springboot源码分析5——后续处理内容

public ConfigurableApplicationContext run(String... args) {
   long startTime = System.nanoTime();
   DefaultBootstrapContext bootstrapContext = createBootstrapContext();
   ConfigurableApplicationContext context = null;
   configureHeadlessProperty();
   SpringApplicationRunListeners listeners = getRunListeners(args);
   listeners.starting(bootstrapContext, this.mainApplicationClass);
   try {
      ApplicationArguments applicationArguments = new DefaultApplicationArguments(args);
      ConfigurableEnvironment environment = prepareEnvironment(listeners, bootstrapContext, applicationArguments);
      configureIgnoreBeanInfo(environment);
      Banner printedBanner = printBanner(environment);
      context = createApplicationContext();
      context.setApplicationStartup(this.applicationStartup);
      prepareContext(bootstrapContext, context, environment, listeners, applicationArguments, printedBanner);
      refreshContext(context);
       //刷新后处理,默认什么都不进行处理,等着你来重写重新实现处理的内容
      afterRefresh(context, applicationArguments);
       //这里记录程序运行时间,和上面刚开始的时候记录的时间相减。
      Duration timeTakenToStartup = Duration.ofNanos(System.nanoTime() - startTime);
      if (this.logStartupInfo) {
         //创建启动日志
         new StartupInfoLogger(this.mainApplicationClass).logStarted(getApplicationLog(), timeTakenToStartup);
      }
       //执行启动事件的监听器,一共有6个(我这里)
      listeners.started(context, timeTakenToStartup);
       //调用ApplicationContext和CommandLineRunner对应的运行的run方法
      callRunners(context, applicationArguments);
   }
   catch (Throwable ex) {
      handleRunFailure(context, ex, listeners);
      throw new IllegalStateException(ex);
   }
   try {
       //计算到进行ready的时间
      Duration timeTakenToReady = Duration.ofNanos(System.nanoTime() - startTime);
       //执行监听器对应的springboot的application的准备类型的监听器。主要就是处理一些后续的工作,比如设置一些状态,发布一些对应的事件。
       //包括你自定义的ListenerRun的run方法也是在这个时候执行的。
      listeners.ready(context, timeTakenToReady);
   }
   catch (Throwable ex) {
      handleRunFailure(context, ex, null);
      throw new IllegalStateException(ex);
   }
   return context;
}

启动事件的监听器

在这里插入图片描述

完成之后返回上下文就初始化完毕了!

Spring Boot启动源码分析6——refresh的invokeBeanFactoryPostProcessors方法详解

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值