簡體   English   中英

在命令行Spring引導中傳遞多個arguments

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM