[英]Passing multiple arguments in command line Spring Boot
我需要将多个 arguments 传递给 maven 命令行来运行 spring 引导应用程序。 这就是我在 spring 引导中传递命令行 arguments 的方式。 我正在使用 spring 启动 2.2.6 版本
mvn spring-boot:run -Dspring-boot.run.arguments="--server.port=8999,--spring.application.instance_id=dhn"
但是我收到以下错误
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
似乎 arguments 没有正确解析
分隔符似乎不起作用。 虽然我已经在教程中看到了这种风格。
有效的是一个空间作为分隔符:
mvn spring-boot:run -Dspring-boot.run.arguments="--server.port=8999 --spring.application.instance_id=dhn"
对于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
为了通过Gradle Command-Line Arguments
首先在build.gradle
文件中配置bootRun
任务:
bootRun {
if (project.hasProperty('args')) {
args project.args.split(',')
}
}
现在将命令行 arguments 传递为:
./gradlew bootRun -Pargs=--server.port=8999,--spring.application.instance_id=dhn
请参阅此快速教程 - Spring Boot 中的命令行 Arguments 以获得广泛的理解。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.