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方法。。

  • 相关阅读:
    二维hash(Uva 12886)
    C#中的线程(一)入门
    全国各地所有高校名单数据库 全国所有高校排名
    协议与代理
    表的约束条件
    na 斐波那契数列f(f(n))
    gcd题目
    Neighbor 隔壁
    hadoop
    Mybatis中实现mysql分页写法!!注意
  • 原文地址:https://www.cnblogs.com/jatpeo/p/11767492.html
Copyright © 2011-2022 走看看