【问题标题】:spring.profiles.active is not working from the command linespring.profiles.active 不能从命令行工作
【发布时间】:2015-05-20 17:04:43
【问题描述】:

我正在使用 spring-boot: 1.2.2

这是docs 中提供的语法(当我开始使用该命令时,我得到Unknown command-line option '--spring.profiles.active'.

gradlew bootRun --spring.profiles.active=noAuthentication

我试过了,但是不行

gradlew bootRun -Dspring.profiles.active=noAuthentication

我在其他地方发现这应该可以,但它没有

gradlew bootRun -Drun.jvmArguments="-Dspring.profiles.active=noAuthentication"

我在 application.properties 中添加了以下内容,它可以正常工作。

spring.profiles.active=noAuthentication

如何从命令行传递这个参数?

【问题讨论】:

  • 您将命令行参数传递给 Gradle,而不是您的 Spring Boot 应用程序。请参阅此答案以了解如何通过 Gradle bootRun stackoverflow.com/questions/25079244/… 将 args 传递给应用程序

标签: spring-boot


【解决方案1】:

修复它通过

project.gradle.projectsEvaluated {
    applicationDefaultJvmArgs = ["-Dspring.profiles.active=${project.gradle.startParameter.systemPropertiesArgs['spring.profiles.active']}"]
}

然后运行

gradlew bootRun -Dspring.profiles.active=prod

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-11
    • 2018-01-24
    • 1970-01-01
    • 2017-08-27
    • 1970-01-01
    • 2011-03-02
    • 2019-06-05
    相关资源
    最近更新 更多