使用参数使用gradle和bootRun运行spring boot应用程序

时间:2018-04-21 16:48:36

标签: java spring-boot gradle build.gradle

我在build.gradle中有以下片段。

buildscript {
    ext {
        springBootVersion = '1.5.12.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}
..
bootRun {
   systemProperties = System.properties
}
..

我使用以下命令运行应用程序。

./gradlew bootRun -PjvmArgs=-Dserver.port=8090

然而它并不起作用。我应该更改为使用指定端口运行应用程序,就像我在application.properties中那样。

server.port=8090

1 个答案:

答案 0 :(得分:2)

使用配置,您应该这样做:

./gradlew bootRun -Dserver.port=8090

使用这段代码:

bootRun {
   systemProperties = System.properties
}

System个属性传递给将要运行的应用程序。 -P用于项目属性。