SpringBoot的配置文件可以给环境变量中的指定key设置value,程序运行时候,从环境中通过key获得value,从而可以实现通过改变配置文件的值,控制程序运行效果,实现业务逻辑。
SpringBoot版本:>=2.4.2(截止文章发布,最高版本2.7.5)
位置优先级:(依次降低)
1> ./config/*/
2> ./config/
3> ./
4> Resources/config/
5> Resorces/
文件类型优先级:(依次降低)
1> .properties
2> .yml
3> .yaml
SpringBoot版本:2.4.1
位置优先级:(依次降低)
1> ./config/*/
2> ./config/
3> ./
4> Resources/config/
5> Resorces/
文件类型优先级:(依次降低)
1> .yaml
2> .yml
3> .properties
SpringBoot版本:2.4.0
位置优先级:(依次降低)
1> ./config/
2> ./config/*/
3> ./
4> Resources/config/
5> Resorces/
文件类型优先级:(依次降低)
1> .yaml
2> .yml
3> .properties
SpringBoot版本:2.3.[0,12].RELEASE
位置优先级:(依次降低)
1> ./config/
2> ./config/*/
3> ./
4> Resources/config/
5> Resorces/
文件类型优先级:(依次降低)
1> .properties
2> .yml
3> .yaml
SpringBoot版本:2.2.x.RELEASE
位置优先级:(依次降低)
1> ./config/
2> 不会去加载./config/*/下的任何配置文件
3> ./
4> Resources/config/
5> Resorces/
文件类型优先级:(依次降低)
1> .properties
2> .yml
3> .yaml
再原始的版本省略,感兴趣自行测试.
指定优先级配置:spring.profiles.active=xxx,该配置项服从以下规则: