Spring boot spring.profiles.active无法从命令行运行

Spring boot spring.profiles.active无法从命令行运行,spring-boot,Spring Boot,我使用的是spring boot:1.2.2 这是I get Unknown命令行选项'-spring.profiles.active'中提供的语法。当我开始使用命令时 gradlew bootRun --spring.profiles.active=noAuthentication 我试过了,但没用 gradlew bootRun -Dspring.profiles.active=noAuthentication 我在其他地方发现,这应该是可行的,但事实并非如此 gradlew bootR

我使用的是spring boot:1.2.2

这是I get Unknown命令行选项'-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
如何从命令行传递此参数?

通过

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

gradlew bootRun -Dspring.profiles.active=prod

您将命令行args传递给Gradle,而不是Spring引导应用程序。查看此答案,了解如何通过Gradle bootRun将参数传递给应用程序