zoukankan      html  css  js  c++  java
  • springboot启动逻辑分析(二)-------简述SpringApplication.run

    调用链路为:

        at org.springframework.boot.SpringApplication.run(SpringApplication.java:296)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
        at com.ivy.demo.DemoApplication.main(DemoApplication.java:16)

    代码:

    public ConfigurableApplicationContext run(String... args) {
            StopWatch stopWatch = new StopWatch();
         //(1).记录开始时间 stopWatch.start(); ConfigurableApplicationContext context
    = null; Collection<SpringBootExceptionReporter> exceptionReporters = new ArrayList<>(); configureHeadlessProperty();
         //(2).获取配置的所有的SpringApplicationRunListener实现类,并封装到SpringApplicationRunListeners类 SpringApplicationRunListeners listeners
    = getRunListeners(args);
         //(3).调用listener列表starting方法 listeners.starting();
    try { ApplicationArguments applicationArguments = new DefaultApplicationArguments( args);
           //(4).准备环境 ConfigurableEnvironment environment
    = prepareEnvironment(listeners, applicationArguments);
           //(5).根据spring.beaninfo.ignore配置是否忽略属性 configureIgnoreBeanInfo(environment);
           //(6).打开欢迎字体 Banner printedBanner
    = printBanner(environment);
           //(7).创建ApplicationContext context
    = createApplicationContext();
           //(8).获取错误报告类 exceptionReporters
    = getSpringFactoriesInstances( SpringBootExceptionReporter.class, new Class[] { ConfigurableApplicationContext.class }, context); prepareContext(context, environment, listeners, applicationArguments, printedBanner); 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, exceptionReporters, listeners); throw new IllegalStateException(ex); } try { listeners.running(context); } catch (Throwable ex) { handleRunFailure(context, ex, exceptionReporters, null); throw new IllegalStateException(ex); } return context; }
  • 相关阅读:
    iTOP-4412开发板低功耗高性能的开源硬件平台——上手评测
    迅为三星Exynos 4412开发板四核Cortex-A9ARM安卓linux开发板
    体验更低功耗的开源硬件平台-迅为4412开发板
    【分享】iTOP-4412开发板使用之初体验[多图]
    【嵌入式开发板】大家都在玩儿的4412开发板
    [POJ] 2965.The Pilots Brothers' refrigerator
    [POJ] 1753.Flip Game
    [HDOJ] 1753.大明A+B (大数加法)
    C++ Primer 第五版 一些遇到的注意点记录。
    [HDOJ] 1172.猜数字
  • 原文地址:https://www.cnblogs.com/itivy/p/11669174.html
Copyright © 2011-2022 走看看