4.SpringBoot 配置及 Nacos 配置中心加载顺序及覆盖生效优先关系
一、测试环境版本
-
spring-boot-starter-parent 2.7.10
-
spring-cloud-starter-bootstrap 3.1.6
-
spring-cloud-starter-alibaba-nacos-config 2021.0.4.0
-
nacos-client 2.1.1
-
nacos 服务端 2.2.1
二、测试结果
1、标准的 SpringBoot 应用
在标准的 SpringBoot 应用中,本地配置加载顺序如下:
- bootstrap 配置 加载先于 application 配置
- 不带 profile 的配置 加载先于 带 profile 的配置
- (不含后缀的) 同文件名配置 *.yaml 加载先于 *.properties
综上,本地加载顺序为:
- bootstrap.yaml
- bootstrap.properties
- bootstrap-{profile}.yaml
- bootstrap-{pro
摘抄自网络,便于检索查找。