Spring Boot yml文件读取顺序

标签 spring spring-boot

我在标准 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.ymlbootstrap-dev.yml

正如您所见 here

bootstrap.yml is loaded before application.yml.

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

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

关于Spring Boot yml文件读取顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71973141/

相关文章:

spring - jetty-maven-plugin 和 loadTimeWeaver

java - Spring URI 模式。在正则表达式路径中使用斜杠

maven - Spring 启动: how do I create a self-contained executable jar?

java - 类型参数 'S' 的推断类型 'S' 不在其范围内;应该扩展 'ua.com.store.entity.Country

java - 使用 spring-boot 在库中设置默认属性

spring - 使用Keycloak和spring boot实现 Multi-Tenancy 应用程序

java - org.springframework.boot.web.support 不存在

java - 无法使用 Spring JPA READ UNCOMMITTED 隔离级别读取未提交的数据

java - Spring AOP : Around aspect not working

spring - Spring tcServer 对 EJB、JAX-WS 的支持