最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SpringBoot啟動(dòng)應(yīng)用及回調(diào)監(jiān)聽原理解析

 更新時(shí)間:2019年12月13日 15:15:13   作者:BINGJJFLY  
這篇文章主要介紹了SpringBoot啟動(dòng)應(yīng)用及回調(diào)監(jiān)聽原理解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

這篇文章主要介紹了SpringBoot啟動(dòng)應(yīng)用及回調(diào)監(jiān)聽原理解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

主類Main方法

public static void main(String[] args) {
  SpringApplication.run(SpringBootRunApplication.class, args);
}

創(chuàng)建SpringApplication對(duì)象

public static ConfigurableApplicationContext run(Class<?>[] primarySources, String[] args) {
  return (new SpringApplication(primarySources)).run(args);
}  

構(gòu)造器

public SpringApplication(ResourceLoader resourceLoader, Class<?>... primarySources) {
  this.sources = new LinkedHashSet();
  this.bannerMode = Mode.CONSOLE;
  this.logStartupInfo = true;
  this.addCommandLineProperties = true;
  this.addConversionService = true;
  this.headless = true;
  this.registerShutdownHook = true;
  this.additionalProfiles = new HashSet();
  this.isCustomEnvironment = false;
  this.lazyInitialization = false;
  this.resourceLoader = resourceLoader;
  Assert.notNull(primarySources, "PrimarySources must not be null");
  this.primarySources = new LinkedHashSet(Arrays.asList(primarySources));
  this.webApplicationType = WebApplicationType.deduceFromClasspath();
  this.setInitializers(this.getSpringFactoriesInstances(ApplicationContextInitializer.class));
  this.setListeners(this.getSpringFactoriesInstances(ApplicationListener.class));
  this.mainApplicationClass = this.deduceMainApplicationClass();
}

ApplicationContextInitializer&ApplicationListener

讀取META-INF/spring.factories文件中的類 

this.setInitializers(this.getSpringFactoriesInstances(ApplicationContextInitializer.class));
this.setListeners(this.getSpringFactoriesInstances(ApplicationListener.class));

執(zhí)行run方法 

public ConfigurableApplicationContext run(String... args) {
  StopWatch stopWatch = new StopWatch();
  stopWatch.start();
  // IOC容器
  ConfigurableApplicationContext context = null;
  Collection<SpringBootExceptionReporter> exceptionReporters = new ArrayList();
  this.configureHeadlessProperty();
  // 讀取META-INF/spring.factories文件獲得SpringApplicationRunListener的實(shí)現(xiàn)類集合
  SpringApplicationRunListeners listeners = this.getRunListeners(args);
  // 監(jiān)聽開始,回調(diào)所有SpringApplicationRunListener的starting()方法
  listeners.starting();
 
  Collection exceptionReporters;
  try {
    ApplicationArguments applicationArguments = new DefaultApplicationArguments(args);
    // 監(jiān)聽配置環(huán)境準(zhǔn)備好了,回調(diào)所有SpringApplicationRunListener的environmentPrepared()方法
    ConfigurableEnvironment environment = this.prepareEnvironment(listeners, applicationArguments);
    this.configureIgnoreBeanInfo(environment);
    Banner printedBanner = this.printBanner(environment);
    // 創(chuàng)建IOC容器
    context = this.createApplicationContext();
    exceptionReporters = this.getSpringFactoriesInstances(SpringBootExceptionReporter.class, new Class[]{ConfigurableApplicationContext.class}, context);
    // 回調(diào)ApplicationContextInitializer的initialize()方法,回調(diào)SpringApplicationRunListener的contextPrepared()方法
    // 回調(diào)SpringApplicationRunListener的contextLoaded()方法
    this.prepareContext(context, environment, listeners, applicationArguments, printedBanner);
    // 刷新IOC容器,注入組件
    this.refreshContext(context);
    this.afterRefresh(context, applicationArguments);
    stopWatch.stop();
    if (this.logStartupInfo) {
      (new StartupInfoLogger(this.mainApplicationClass)).logStarted(this.getApplicationLog(), stopWatch);
    }
    // 回調(diào)SpringApplicationRunListener的started()方法
    listeners.started(context);
    // 從IOC容器中獲得ApplicationRunner、CommandLineRunner的所有組件,回調(diào)ApplicationRunner、CommandLineRunner的run()方法
    this.callRunners(context, applicationArguments);
  } catch (Throwable var10) {
    this.handleRunFailure(context, var10, exceptionReporters, listeners);
    throw new IllegalStateException(var10);
  }
 
  try {
    // 回調(diào)SpringApplicationRunListener的running()方法
    listeners.running(context);
    return context;
  } catch (Throwable var9) {
    this.handleRunFailure(context, var9, exceptionReporters, (SpringApplicationRunListeners)null);
    throw new IllegalStateException(var9);
  }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 教你如何測(cè)試Spring Data JPA的Repository

    教你如何測(cè)試Spring Data JPA的Repository

    Spring Data JPA 提供了一些便捷的方式來測(cè)試這種持久層的代碼,常見的兩種測(cè)試類型是集成測(cè)試和單元測(cè)試,本文通過示例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧
    2024-08-08
  • Java開發(fā)工具IntelliJ IDEA安裝圖解

    Java開發(fā)工具IntelliJ IDEA安裝圖解

    這篇文章主要介紹了Java開發(fā)工具IntelliJ IDEA安裝圖解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-11-11
  • java11新特性之集合轉(zhuǎn)換為數(shù)組的方法

    java11新特性之集合轉(zhuǎn)換為數(shù)組的方法

    Java11引入了一種將帶有泛型的集合轉(zhuǎn)換為帶有泛型的數(shù)組的簡(jiǎn)單方法,本文通過實(shí)例代碼介紹java11新特性之集合轉(zhuǎn)換為數(shù)組的操作方法,感興趣的朋友跟隨小編一起看看吧
    2024-06-06
  • java使用正則表達(dá)校驗(yàn)手機(jī)號(hào)碼示例(手機(jī)號(hào)碼正則)

    java使用正則表達(dá)校驗(yàn)手機(jī)號(hào)碼示例(手機(jī)號(hào)碼正則)

    這篇文章主要介紹了java使用正則表達(dá)校驗(yàn)手機(jī)號(hào)碼示例,可校驗(yàn)三個(gè)號(hào)碼段:13*、15*、18*,大家根據(jù)自己的需要增加自己的號(hào)碼段就可以了
    2014-03-03
  • Spring Boot集成Mybatis的實(shí)例代碼(簡(jiǎn)潔版)

    Spring Boot集成Mybatis的實(shí)例代碼(簡(jiǎn)潔版)

    這篇文章主要介紹了Spring Boot集成Mybatis簡(jiǎn)潔版的教程,需要的朋友可以參考下
    2018-02-02
  • Java中的線程生命周期核心概念

    Java中的線程生命周期核心概念

    這篇文章主要介紹了Java中的線程生命周期核心概念,通過使用一個(gè)快速的圖解展開文章內(nèi)容,需要的小伙伴可以參考一下
    2022-06-06
  • Springboot2整合knife4j過程解析

    Springboot2整合knife4j過程解析

    這篇文章主要介紹了Springboot2整合knife4j過程解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-03-03
  • 使用Java快速將Web中表格轉(zhuǎn)換成Excel的方法

    使用Java快速將Web中表格轉(zhuǎn)換成Excel的方法

    在平時(shí)做系統(tǒng)項(xiàng)目時(shí),經(jīng)常會(huì)需要做導(dǎo)出功能,下面這篇文章主要給大家介紹了關(guān)于使用Java快速將Web中表格轉(zhuǎn)換成Excel的相關(guān)資料,需要的朋友可以參考下
    2023-06-06
  • Java實(shí)現(xiàn)聊天機(jī)器人完善版

    Java實(shí)現(xiàn)聊天機(jī)器人完善版

    這篇文章主要為大家詳細(xì)介紹了Java實(shí)現(xiàn)聊天機(jī)器人完善版,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-07-07
  • Java泛型之類型擦除實(shí)例詳解

    Java泛型之類型擦除實(shí)例詳解

    Java泛型在使用過程有諸多的問題,如不存在List<String>.class,List<Integer>不能賦值給List<Number>(不可協(xié)變),奇怪的ClassCastException等,這篇文章主要給大家介紹了關(guān)于Java泛型之類型擦除的相關(guān)資料,需要的朋友可以參考下
    2022-01-01

最新評(píng)論

晋宁县| 木兰县| 墨竹工卡县| 思南县| 高陵县| 阿坝| 理塘县| 钟祥市| 黎川县| 漠河县| 苗栗县| 临颍县| 铜陵市| 垣曲县| 芒康县| 合肥市| 虎林市| 峨山| 比如县| 北票市| 永善县| 德安县| 乌兰浩特市| 北京市| 太湖县| 灵山县| 江城| 鄯善县| 杭锦后旗| 古浪县| 蓬莱市| 九寨沟县| 延寿县| 大兴区| 河间市| 胶州市| 三江| 勃利县| 桐梓县| 陆河县| 吉木乃县|