spring 什么时候使用 application-dev.properties 和 application.properties

Mik*_*yev 2 intellij-idea maven spring-boot application.properties

我有几个 Spring Boot 应用程序。它们都是 maven 项目,并且在所有项目中,我都有针对不同环境的单独配置文件,例如 application.properties、application-dev.properties、application-uat.properties。当我从 IDE 运行应用程序时,它有时从 application.properties 文件中读取,有时从 application-dev.properties 文件中读取。我使用 IntelliJ IDEA 进行开发,但我一直无法弄清楚是什么决定了要读取哪个文件。是依赖于 IDE 还是 Spring 中有一些配置决定选择哪个属性文件?

Nik*_*kem 8

很可能你在 Idea 中的一些运行配置已经配置了 Spring “配置文件”来运行。当您使用例如“dev”配置application-dev.properties文件运行 Spring Boot 应用程序时,除了application.properties. 见这里获取更多信息

  • 谢谢你的“除了”。我在 application.properties 中配置了一个属性,但未在 application-dev.properties 中定义。因此使用了第一个文件中的属性,这破坏了应用程序。 (3认同)