[英]Passing multiple arguments in command line Spring Boot
I need to pass multiple arguments to maven command line to run a spring boot application.我需要将多个 arguments 传递给 maven 命令行来运行 spring 引导应用程序。 This is how I was passing command line arguments in spring boot.
这就是我在 spring 引导中传递命令行 arguments 的方式。 I am using spring boot 2.2.6 Release
我正在使用 spring 启动 2.2.6 版本
mvn spring-boot:run -Dspring-boot.run.arguments="--server.port=8999,--spring.application.instance_id=dhn"
mvn spring-boot:run -Dspring-boot.run.arguments="--server.port=8999,--spring.application.instance_id=dhn"
However I get the following error但是我收到以下错误
nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'server.port' to java.lang.Integer
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to bind properties under 'server.port' to java.lang.Integer:
Property: server.port
Value: 8999,--spring.application.instance_id=dhn
Origin: "server.port" from property source "commandLineArgs"
Reason: failed to convert java.lang.String to java.lang.Integer
Action:
Update your application's configuration
Seems like the arguments are not parsed correctly似乎 arguments 没有正确解析
The, separator seems not to work.分隔符似乎不起作用。 Although I already saw this style in tutorials.
虽然我已经在教程中看到了这种风格。
What works is a space as seprator:有效的是一个空间作为分隔符:
mvn spring-boot:run -Dspring-boot.run.arguments="--server.port=8999 --spring.application.instance_id=dhn"
For Maven Command-Line Arguments
you can pass the arguments using -Dspring-boot.run.arguments
without wrapping it in double quotes like:对于
Maven Command-Line Arguments
,您可以使用-Dspring-boot.run.arguments
传递 arguments
mvn spring-boot:run -Dspring-boot.run.arguments=--server.port=8999,--spring.application.instance_id=dhn
mvn spring-boot:run -Dspring-boot.run.arguments=--server.port=8999,--spring.application.instance_id=dhn
For passing Gradle Command-Line Arguments
first configure the bootRun
task in build.gradle
file as:为了通过
Gradle Command-Line Arguments
首先在build.gradle
文件中配置bootRun
任务:
bootRun {
if (project.hasProperty('args')) {
args project.args.split(',')
}
}
now pass the command-line arguments as:现在将命令行 arguments 传递为:
./gradlew bootRun -Pargs=--server.port=8999,--spring.application.instance_id=dhn
./gradlew bootRun -Pargs=--server.port=8999,--spring.application.instance_id=dhn
Refer to this quick tutorial - Command-Line Arguments in Spring Boot for an extensive understanding.请参阅此快速教程 - Spring Boot 中的命令行 Arguments 以获得广泛的理解。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.