Override yml configuration in spring-boot with command line arguments

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

java -jar --input=user2 
+6
source share
1 answer

To develop a cLyric answer , you can do this:

 java -jar yourapp.jar --input=user2 

Or, if you want to use json, you can do

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

Or if you are working on unix / linux,

 SPRING_APPLICATION_JSON='{"input":"user2"}' java -jar yourapp.jar 
+1
source

Source: https://habr.com/ru/post/985530/


All Articles