问题描述
简单的问题是:如何用gradle更改Spring Boot应用程序端口?
已经列出很多正确的答案,如果你不使用gradle。如果您还没有使用 add它到您的构建脚本(当然,适应Spring Boot版本以满足您的需求):
buildscript {
ext {springBootVersion ='1.5.7.RELEASE'}
依赖关系{
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}]
}
然后您可以使用 $ b
如果在此示例中跳过了-Pport,它将使用8080。
The simple question is: How can you change the Spring Boot application port with gradle?
Here are already listed a lot of correct answers if you are not using gradle. So for none gradle issues, please refere to this post.
If you're not already using the Spring Boot Gradle Plugin add it to your build script (of course, adapt the Spring Boot version to your needs):
buildscript{
ext { springBootVersion = '1.5.7.RELEASE' }
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'org.springframework.boot'
With this plugin you can do the following:
bootRun {
args += ["--server.port=[PORT]"]
}
For more dynamic you can use a project property to change the port. You have to do something similar like this:
if(!project.hasProperty("port"))
project.ext.set("port", 8080)
bootRun {
args += ["--server.port=${project.port}"]
}
Then you can start the application with
If you skip the -Pport in this example it will use 8080.
这篇关于如何使用Gradle更改Spring Boot应用程序的端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!