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

综上,本地加载顺序为

  1. bootstrap.yaml
  2. bootstrap.properties
  3. bootstrap-{profile}.yaml
  4. bootstrap-{pro
posted @ 2024-06-27 14:12  CharyGao  阅读(179)  评论(0编辑  收藏  举报