6

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

2 Answers 2

17

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"
Sign up to request clarification or add additional context in comments.

2 Comments

Space separator does not work for me with Spring-boot 2.1.5
It seems space works from 2.2.x. github.com/spring-projects/spring-boot/pull/18711
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.