星空网 > 软件开发 > Java

附4 springboot源码解析

 1   public ConfigurableApplicationContext run(String... args) { 2     StopWatch stopWatch = new StopWatch();              //设置计时器 3     stopWatch.start();                        //记录当前时间 4     ConfigurableApplicationContext context = null; 5     configureHeadlessProperty();                  //设置java.awt.headless为true或false 6     SpringApplicationRunListeners listeners = getRunListeners(args);//获取事件发布器(控制所有事件的执行时机) 7     listeners.started();                      //事件发布器发布ApplicationStartedEvent事件,所有监听了该事件的ApplicationListener实现类执行逻辑 8     try { 9       context = doRun(listeners, args);10       stopWatch.stop();                      //计时结束(记录总共花了多少时间)11       if (this.logStartupInfo) {12         new StartupInfoLogger(this.mainApplicationClass)13             .logStarted(getApplicationLog(), stopWatch);14       }15       return context;16     }17     catch (Throwable ex) {18       handleRunFailure(context, listeners, ex);19       throw new IllegalStateException(ex);20     }21   }

 1   private ConfigurableApplicationContext doRun(SpringApplicationRunListeners listeners, 2       String... args) { 3     ConfigurableApplicationContext context; 4     // Create and configure the environment 5     ConfigurableEnvironment environment = getOrCreateEnvironment(); //创建Environment 6     configureEnvironment(environment, args);            //配置Environment(包括配置要使用的PropertySource和Profile) 7     listeners.environmentPrepared(environment);            //事件发布器发布ApplicationEnvironmentPreparedEvent事件,所有监听了该事件的ApplicationListener执行相应逻辑 8     if (isWebEnvironment(environment) && !this.webEnvironment) { 9       environment = convertToStandardEnvironment(environment);10     }11 12     if (this.bannerMode != Banner.Mode.OFF) {13       printBanner(environment);14     }15 16     // Create, load, refresh and run the ApplicationContext17     context = createApplicationContext();              //创建ApplicationContext容器18     context.setEnvironment(environment);              //设置Environment到容器19     postProcessApplicationContext(context);              20     applyInitializers(context);                    //执行所有的ApplicationContextInitializer的initial方法,对创建出来的ApplicationContext容器进行初始化21     listeners.contextPrepared(context);                22     if (this.logStartupInfo) {23       logStartupInfo(context.getParent() == null);24       logStartupProfileInfo(context);25     }26 27     // Add boot specific singleton beans28     ApplicationArguments applicationArguments = new DefaultApplicationArguments(args);29     context.getBeanFactory().registerSingleton("springApplicationArguments",30         applicationArguments);31 32     // Load the sources33     Set<Object> sources = getSources();34     Assert.notEmpty(sources, "Sources must not be empty");35     load(context, sources.toArray(new Object[sources.size()]));    //将之前通过@EnableAutoConfiguration的所有配置以及其他形式的IOC容器加载到已经准备完毕的ApplicationContext36     listeners.contextLoaded(context);                //事件发布器将所有的ApplicationListener注册给当前的ApplicationContext,之后发布ApplicationPreparedEvent事件37 38     // Refresh the context39     refresh(context);                        //刷新ApplicationContext40     if (this.registerShutdownHook) {41       try {42         context.registerShutdownHook();43       }44       catch (AccessControlException ex) {45         // Not allowed in some environments.46       }47     }48     afterRefresh(context, applicationArguments);49     listeners.finished(context, null);50     return context;51   }

 




原标题:附4 springboot源码解析

关键词:Spring

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

海运马来西亚怎么收费:https://www.goluckyvip.com/tag/92300.html
马来西亚海运怎么收费:https://www.goluckyvip.com/tag/92301.html
海运马来西亚整柜价格一览表:https://www.goluckyvip.com/tag/92302.html
到马来西亚海运价格:https://www.goluckyvip.com/tag/92303.html
马来西亚的海运价格:https://www.goluckyvip.com/tag/92304.html
海运至马来西亚价格:https://www.goluckyvip.com/tag/92305.html
湘西游轮六 湘江游轮夜游:https://www.vstour.cn/a/411226.html
携程旅游网折扣优惠最新攻略(携程旅游网更佳折扣优惠):https://www.vstour.cn/a/411227.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流