How To Override Application Properties Using External Configuration

Step-by-Step Guide


  1. Override using CLI arguments
    Overriding properties is done by using the java -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.

  2. 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 the java -jar command.
    To test this use case:
    1. Download and unzip demo-0.1.zip.
    2. Download application.yml file in the same folder of the extracted jar file
    3. Open Terminal and run java -jar demo.0.1.jar command
    This will expose the endpoint at localhost:8080/home

Attachments

application.yml
demo-0.1.zip

Spring Boot External Configuration

Filter by label

There are no items with the selected labels at this time.