zoukankan      html  css  js  c++  java
  • 7_1.springboot2.x启动配置原理_1.创建SpringApplication对象

    环境准备

    springboot2.1.9、idea2019、

    pom.xml

    解析

    几个重要的事件回调机制
    配置在META-INF/spring.factories
    ApplicationContextInitializer
    SpringApplicationRunListener


    只需要放在ioc容器中
    ApplicationRunner
    CommandLineRunner

    在主配置类打断点进行调试

    可见springboot应用程序分为两步:1、创建SpringApplication对象;2、运行run方法

    创建SpringApplication对象

    	public SpringApplication(ResourceLoader resourceLoader, Class<?>... primarySources) {
    		this.resourceLoader = resourceLoader;
            //判断主配置类不能为空
    		Assert.notNull(primarySources, "PrimarySources must not be null");
            //保存主配置类
    		this.primarySources = new LinkedHashSet<>(Arrays.asList(primarySources));
            //判断当前是否一个web应用
    		this.webApplicationType = WebApplicationType.deduceFromClasspath();
    //从类路径下找到META‐INF/spring.factories配置的所有ApplicationContextInitializer;然后保存
    		setInitializers((Collection) getSpringFactoriesInstances(ApplicationContextInitializer.class));
    //从类路径下找到ETA‐INF/spring.factories配置的所有ApplicationListener
    		setListeners((Collection) getSpringFactoriesInstances(ApplicationListener.class));
    //从多个配置类中找到有main方法的主配置类
    		this.mainApplicationClass = deduceMainApplicationClass();
    	}
    setInitializers((Collection) getSpringFactoriesInstances(ApplicationContextInitializer.class));

    setListeners((Collection) getSpringFactoriesInstances(ApplicationListener.class));
    

    查看已创建的SpringApplication对象:

    之后运行run方法。。

  • 相关阅读:
    一个购物网站的思路设计分享
    B/S和C/S的区别(转)
    TreeSet
    计算出给你一个随机乱敲的一个字符串最多的一个
    JavaScript来实现打开链接页面(转载)
    js小数计算小数点后显示多位小数(转)
    java中使用 正则 抓取邮箱
    浅谈 正则表达式
    jQuery中each()、find()、filter()等节点操作方法
    Xcode插件VVDocumenter Alcatraz KSImageNamed等安装
  • 原文地址:https://www.cnblogs.com/jatpeo/p/11767492.html
Copyright © 2011-2022 走看看