为 Spring Profile 提供配置文件名称

问题描述

我通过在 application.properties 文件中设置属性 spring.profiles.active 在我的 Spring Boot 应用程序中使用 Spring Profiles。

但是如果我使用 JVM 系统参数的方式提供配置文件名称,并且 spring.profiles.active 属性仍然存在于文件中,它会覆盖文件值吗?

JVM系统参数方式:

-Dspring.profiles.active=dev

解决方法

它将出现在文件中。命令行参数将优先于文件属性。

这些配置文件将在应用程序启动期间激活。