我在标准 Spring Boot 应用程序的资源文件夹下有以下文件。 spring.active.profile设置为dev 属性文件按什么顺序读取。?
1)application.yml
2)bootstrap.yml
3)application_dev.yml
4)bootstrap_dev.yml
最佳答案
如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.yml
和bootstrap-dev.yml
正如您所见 here
bootstrap.yml is loaded before application.yml.
所以要回答你的问题,顺序应该是
- bootstrap.yml
- bootstrap_dev.yml
- application.yml
- application_dev.yml
关于Spring Boot yml文件读取顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71973141/