Spring启动yml文件读取顺序

Spring Boot yml file read order

我在标准 Spring 启动应用程序的资源文件夹下有以下文件。 Spring.active.profile 设置为开发 属性文件的读取顺序是什么?

1)application.yml 
2)bootstrap.yml
3)application_dev.yml
4)bootstrap_dev.yml

bootstrap 文件总是第一个:bootstrap.yml 然后是 bootstrap-{profile}.yml。然后 application.yml 和 application-{profile}.yml.

属性 值被下一个文件覆盖,因此: 来自 application.yml 的 a: 1 将被来自 application-{profile}.yml

a: 55 覆盖

Spring doc所述

Profile specific properties are loaded from the same locations as standard application.properties, with profiles specific files overriding the default ones

这意味着首先读取 application.yml,然后读取 application_dev.yml,并在需要时覆盖默认值 application.yml

bootstrap.ymlbootstrap-dev.yml

相同

也如你所见

bootstrap.yml is loaded before application.yml.

所以要回答你的问题,顺序应该是

  1. bootstrap.yml
  2. bootstrap_dev.yml
  3. application.yml
  4. application_dev.yml