Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override yml configuration in spring-boot with command line arguments

I have a spring-boot application that is configured with a yml file. Is it possible to override these properties when executing the jar? For example let say I have the input variable in yml file set to user1 and I want to execute the jar with user2. Is it possible to do something like this?

java -jar --input=user2
like image 859
salvador Avatar asked Apr 20 '15 15:04

salvador


1 Answers

To elaborate answer by cLyric, you can do this:

java -jar yourapp.jar --input=user2

Or if you want to provide using json, you can do

java -jar yourapp.jar --spring.application.json='{"input":"user2"}'

Or if you're in unix/linux,

SPRING_APPLICATION_JSON='{"input":"user2"}' java -jar yourapp.jar 
like image 140
eis Avatar answered Oct 17 '22 14:10

eis