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

  • 相关阅读:
    Linear Predictors
    Non-Programmer's Tutorial for Python 3/File IO
    Python File I/O
    Introduction to Machine Learning
    Python3.6爬虫+Djiago2.0+Mysql --数据爬取
    MySql5.7 找回密码
    pyinstaller 打包python3.6文件成exe 运行
    python 连接mssql数据库
    Nopi 导出设置行高
    python登录aspx网站
  • 原文地址:https://www.cnblogs.com/jatpeo/p/11767492.html
Copyright © 2011-2022 走看看