为什么run.profiles会被spring-boot忽略:run?

时间:2018-01-04 09:41:09

标签: maven spring-boot spring-boot-maven-plugin

使用spring-boot-maven-plugin版本1.5.9.RELEASE。 documentation使用-Drun.profiles来激活活动配置文件。但是在命令行上运行时,配置文件未激活:

mvn spring-boot:run -Drun.profiles=development

使用jvmArguments参数有效并且配置文件处于活动状态:

mvn spring-boot:run -Drun.jvmArguments="-Dspring.profiles.active=development"

参考: https://github.com/spring-projects/spring-boot/issues/1095

更新

事实证明,配置文件已正确加载。由于条件配置Logback,仅禁用了日志记录:

在Logback配置中,我使用了<if condition='property("spring.profiles.active").contains("development")'>之类的语句。使用带有-Drun.profiles的Maven插件不会设置系统属性spring.profiles.active,而是设置命令行参数(--spring.profiles.active)。

因此,在Logback中使用条件语句时,只能使用系统属性和环境变量。

1 个答案:

答案 0 :(得分:1)

确保您有application-development.properties文件。否则创建它并将您的属性放在那里。默认情况下,将考虑并执行application.properties。

根据配置文件,您已创建相应的应用程序属性文件。