SpringBoot启动源码跟踪与注释

参照:https://blog.csdn.net/sessionsong/article/details/86682808 

public SpringApplication(ResourceLoader resourceLoader, Class<?>... primarySources) {
        this.sources = new LinkedHashSet(); // 初始化
        this.bannerMode = Mode.CONSOLE; // 控制台
        this.logStartupInfo = true; // 打印log
        this.addCommandLineProperties = true; //
        this.addConversionService = true;
        this.headless = true;
        this.registerShutdownHook = true; 
        this.additionalProfiles = new HashSet();
        this.isCustomEnvironment = false;
        this.resourceLoader = resourceLoader; // null值的loader
        // primarySources是否为null
        Assert.notNull(primarySources, "PrimarySources must not be null");
        // 初始化并去重
        this.primarySources = new LinkedHashSet(Arrays.asList(primarySources)); 
        // 类型 REACTIVE  SERVLET NONE
        this.webApplicationType = WebApplicationType.deduceFromClasspath(); 
       // 初始化上下文             
 this.setInitializers(this.getSpringFactoriesInstances(ApplicationContextInitializer.class)); 
        // 监听
        this.setListeners(this.getSpringFactoriesInstances(ApplicationListener.class));
        // 主入口  一般是Class.forName(启动类)
        this.mainApplicationClass = this.deduceMainApplicationClass();
}
// spring 秒表
StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        ConfigurableApplicationContext context = null;
        Collection<SpringBootExceptionReporter> exceptionReporters = new ArrayList();
        this.configureHeadlessProperty();
// 创建并启动监听
        SpringApplicationRunListeners listeners = this.getRunListeners(args);
        listeners.starting();

        Collection exceptionReporters;
        try {
// 初始化默认应用参数
            ApplicationArguments applicationArguments = new DefaultApplicationArguments(args);
// 根据监听准备spring环境
            ConfigurableEnvironment environment = this.prepareEnvironment(listeners, applicationArguments);
            this.configureIgnoreBeanInfo(environment);
// 创建banner打印
            Banner printedBanner = this.printBanner(environment);
// 创建上下文
            context = this.createApplicationContext();
            exceptionReporters = 
// 异常报告器
this.getSpringFactoriesInstances(SpringBootExceptionReporter.class, new Class[]{ConfigurableApplicationContext.class}, context);
            this.prepareContext(context, environment, listeners, applicationArguments, printedBanner);
// 刷新应用上下文
            this.refreshContext(context);
// 应用上下文刷新后置处理
            this.afterRefresh(context, applicationArguments);
// 停止秒表
            stopWatch.stop();
            if (this.logStartupInfo) {
// 输出日志
                (new StartupInfoLogger(this.mainApplicationClass)).logStarted(this.getApplicationLog(), stopWatch);
            }
// 启动监听
            listeners.started(context);
// 发布应用上下文启动完成
            this.callRunners(context, applicationArguments);
        } catch (Throwable var10) {
            this.handleRunFailure(context, var10, exceptionReporters, listeners);
            throw new IllegalStateException(var10);
        }

        try {
// 执行所有runner
            listeners.running(context);
// 发布应用上下文就绪事件
            return context;
        } catch (Throwable var9) {
            this.handleRunFailure(context, var9, exceptionReporters, (SpringApplicationRunListeners)null);
            throw new IllegalStateException(var9);
        }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值