Reputation: 53
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
Upvotes: 5
Views: 12369
Reputation: 1090
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.
Upvotes: 0
Reputation: 36223
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"
Upvotes: 15