我有几个 Spring Boot 应用程序。它们都是 maven 项目,并且在所有项目中,我都有针对不同环境的单独配置文件,例如 application.properties、application-dev.properties、application-uat.properties。当我从 IDE 运行应用程序时,它有时从 application.properties 文件中读取,有时从 application-dev.properties 文件中读取。我使用 IntelliJ IDEA 进行开发,但我一直无法弄清楚是什么决定了要读取哪个文件。是依赖于 IDE 还是 Spring 中有一些配置决定选择哪个属性文件?
最佳答案
很可能你在 Idea 中的一些运行配置已经配置了 Spring “配置文件”来运行。当您使用例如“dev”配置文件运行 Spring Boot 应用程序时,然后 application-dev.properties
除了 application.properties
之外,还将读取文件.见 here欲了解更多信息
关于maven - spring 什么时候使用 application-dev.properties 和 application.properties,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50522397/