springboot配置文件加载顺序,配置文件优先级

1. 若application.yml 和bootStrap.yml 在同一目录下,则bootStrap.yml 的加载顺序要高于application.yml,即bootStrap.yml  会优先被加载。

   原理:bootstrap.yml 用于应用程序上下文的引导阶段。

              bootstrap.yml 由父Spring ApplicationContext加载。

            •bootstrap.yml 可以理解成系统级别的一些参数配置,这些参数一般是不会变动的。
            •application.yml 可以用来定义应用级别的,如果搭配 spring-cloud-config 使用 application.yml 里面定义的文件可以实现动态替换。

 

 

2. 不同位置的配置文件的加载顺序:

   在不指定要被加载文件时,默认的加载顺序:由里向外加载,所以最外层的最后被加载,会覆盖里层的属性(参考官网介绍)

SpringApplication will load properties from application.properties files in the following locations and add them to the Spring Environment: 

A /config subdirectory of the current directory.    //位于与jar包同级目录下的config文件夹,
The current directory                             //位于与jar包同级目录下
A classpath /config package          //idea 环境下,resource文件夹下的config文件夹
The classpath

你可能感兴趣的:(springboot配置文件加载顺序,配置文件优先级)