spring-boot启动

public ConfigurableApplicationContext run(String... args) {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    //创建引导上下文
    DefaultBootstrapContext bootstrapContext = createBootstrapContext();
    ConfigurableApplicationContext context = null;
    configureHeadlessProperty();
    
    //生成启动监视器
    SpringApplicationRunListeners listeners = getRunListeners(args);
    
    //resources下创建META-INF/spring.factories文件
    //加载监听器如下方
    //org.springframework.boot.SpringApplicationRunListener=\
    //org.springframework.boot.context.event.EventPublishingRunListener
    listeners.starting(bootstrapContext, this.mainApplicationClass);
    try {
       //初始化应用参数类
       ApplicationArguments applicationArguments = new DefaultApplicationArguments(args);
        
       //准备环境参数
       ConfigurableEnvironment environment = prepareEnvironment(listeners, bootstrapContext, applicationArguments);
       configureIgnoreBeanInfo(environment);
        
       //打印图像控制台
       Banner printedBanner = printBanner(environment);
        
       //创建spring上下文
       context = createApplicationContext();
       context.setApplicationStartup(this.applicationStartup);
        
       //准备上下文
       //完成事件ApplicationContextInitializedEvent
       //完成事件ApplicationPreparedEvent
       prepareContext(bootstrapContext, context, environment, listeners, applicationArguments, printedBanner);
        
       //刷新上下文
       //上下文刷新完成事件ContextRefreshedEvent
       //Web服务器完成事件WebServerlnitializedEvent
       refreshContext(context);
        
       afterRefresh(context, applicationArguments);
       stopWatch.stop();
       if (this.logStartupInfo) {
          new StartupInfoLogger(this.mainApplicationClass).logStarted(getApplicationLog(), stopWatch);
       }
       listeners.started(context);
       callRunners(context, applicationArguments);
    }
    catch (Throwable ex) {
       handleRunFailure(context, ex, listeners);
       throw new IllegalStateException(ex);
    }

    try {
       listeners.running(context);
    }
    catch (Throwable ex) {
       handleRunFailure(context, ex, null);
       throw new IllegalStateException(ex);
    }
    return context;
}
posted @   辉辉、  阅读(5)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示