简体   繁体   中英

Passing multiple arguments in command line Spring Boot

I need to pass multiple arguments to maven command line to run a spring boot application. This is how I was passing command line arguments in spring boot. I am using spring boot 2.2.6 Release

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

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:

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:

bootRun {
    if (project.hasProperty('args')) {
        args project.args.split(',')
    }
}

now pass the command-line arguments as:

./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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM