How To Override Application Properties Using External Configuration
Step-by-Step Guide
Override using CLI arguments
Overriding properties is done by using thejava -jar
command and setting the properties as-Dproperty.name=value
e.g.,java -jar -Dproperty.name=value executable-jar-name.jar
To test this use case, download and unzip demo-0.1.zip.
By default, the Spring Boot app runs and exposes endpoint at localhost:8090/home
To override the property, open a terminal and run the following command:java -jar -Dserver.port=8080 demo-0.1.jar
This will expose the endpoint at localhost:8080/home.
- Override Uuing External application.yml file
Another option to override properties is by using an external application.yml/application.properties file.
This file should have the same structure of properties to be overridden, and be at the same path that we execute thejava -jar
command.
To test this use case:- Download and unzip demo-0.1.zip.
- Download application.yml file in the same folder of the extracted jar file
- Open Terminal and run
java -jar demo.0.1.jar
command
Attachments
Related articles
Spring Boot External Configuration