【发布时间】:2018-04-22 05:25:18
【问题描述】:
【问题讨论】:
标签: spring-boot gradle port
【问题讨论】:
标签: spring-boot gradle port
如果您还没有使用Spring Boot Gradle Plugin,请将其添加到您的构建脚本中(当然,根据您的需要调整 Spring Boot 版本):
buildscript{
ext { springBootVersion = '1.5.7.RELEASE' }
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'org.springframework.boot'
使用此插件,您可以执行以下操作:
bootRun {
args += ["--server.port=[PORT]"]
}
或者更动态您可以使用项目属性来更改端口。你必须做类似这样的事情:
if(!project.hasProperty("port"))
project.ext.set("port", 8080)
bootRun {
args += ["--server.port=${project.port}"]
}
然后就可以用
启动应用了./gradlew bootRun -Pport=8888
如果您在本例中跳过 -Pport,它将使用 8080。
【讨论】:
如果您不想在 Gradle 脚本中添加额外的配置,可以通过设置 SERVER_PORT 环境变量来实现:
SERVER_PORT=8888 ./gradlew bootRun
[更新]自 Gradle 4.9 起,无需额外配置即可pass arguments to bootRun:
./gradlew bootRun --args='--server.port=8888'
【讨论】: