Externalizing an environmental configuration using environment variables

In the previous recipes, we have, a number of times, alluded to the fact that configuration values to a Spring Boot application can be passed and overridden by using OS environment variables. Operating systems rely on these variables to store information about various things. We probably have to set JAVA_HOME or PATH a few times, and these are examples of environment variables. OS environment variables is also a very important feature if one deploys their application using a PaaS system such as Heroku or Amazon AWS. In these environments, configuration values such as database access credentials and various API tokens are all provided over the environment variables.

Their power comes from the ability to completely externalize the configuration of simple key-value data pairs without the need to rely on placing a property or some other files in a particular location, and having this hardcoded in the application code base. These variables are also agnostic to the particular operating system and can be consumed in the Java program in the same way, System.getenv(), regardless of which OS the program is running on.

In this recipe, we will explore how this power can be leveraged to pass the configuration properties to our Spring Boot applications. We will continue to use the code base from the previous recipe and experiment with a few different ways of starting the application and using the OS environment variables in order to change the configuration values of some properties.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.69.151