



























加载规则
优先级从高到低为
相同配置高优先级覆盖低优先级,不同配置互补,优先级从高到低为
总之注解根据不同条件判断,决定这个配置类是否生效
logging.file=spring.log - 不指定路径就在当前项目下生成spring。log文件 logging.path=/spring/boot - 磁盘根路径下创建 /spring/boot/spring.log日志文件,spring.log是默认文件名 logging.pattern.console= logging.pattern.file= - 设置日志输出格式logback : logback.xml logback-spring.xml
log4j2 : log4j2.xml log4j2-spring.xml
jul: logging.properties
不带`-spring`后缀的,直接被日志框架识别
带后缀的不被日志框架加载,而由spring boot加载,可是使用spring profile功能,指定某个配置在某个环境生效
application-{profile}.properties
---在yml 中可以充当文档块将多个文档分割,每一块用不同的配置
配置文件指定
spring.profiles.active=dev
命令行参数
--spring.profiles.active=dev
虚拟机参数
-Dspring.profiles.active=dev
创建SpringApplication对象
1.扫描类路径下META-INF/spring.factories文件寻找org.springframework.context.ApplicationContextInitializer
对应的类,并保存起来
2.扫描类路径下META-INF/spring.factories文件寻找org.springframework.context.ApplicationListener对应的类
并保存
3.判断传入的配置类,哪一个有主方法,哪个就是主配置类(SpringBoot配置类在启动时可以传多个)
运行run方法
1.获取SpringApplicationRunListeners :扫描类路径下META-INF/spring.factories文件寻找org.springframework.boot.SpringApplicationRunListener并逐个调用starting方法
2.使用ApplicationArguments封装命令行参数
3.创建和配置环境
4.创建和配置环境完成后SpringApplicationRunListeners逐个调用envermentPrepared方法,环境准备完成
5.打印banner图标
6.创建IOC容器,会判断是创建web的容器还是普通类型的容器
7.准备上下文环境
8.回调之前保存的所有ApplicationContextInitializer对象的initialize方法
9.回调所有SpringApplicationRunListener的contextPrepared方法
10.所有配置都完成后,回调所有SpringApplicationRunListener的contextLoaded方法, 然后刷新IOC容器(扫描配置文件配置类,创建对象等。如果是web应用还会创建嵌入式的tomcat)
11.从容器中获取所有的ApplicationRunner和CommandLineRunner进行回调
12.回调所有SpringApplicationRunListener的finish方法,启动完成
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。