How to do it...

  1. In the previous recipe, we added a configuration property named my.config.value. Let's build the application by running ./gradlew clean bootJar and start it by running MY_CONFIG_VALUE="From ENV Config" ./build/libs/bookpub-0.0.1-SNAPSHOT-exec.jar --spring.profiles.active=logger so as to see the following output in the logs:
    2017-12-17 --- ication$$EnhancerBySpringCGLIB$$b123df6a : Value of 
my.config.value property is: From ENV Config
  1. If we want to use the environment variables while running our application via the Gradle bootRun task, the command line will be MY_CONFIG_VALUE="From ENV Config" ./gradlew clean bootRun and should produce the same output as in the preceding step.
  2. Conveniently enough, we can even mix and match how we set the configurations. We can use the environment variable to configure the spring.config.location property and use it to load other property values from the external properties file, as we did in the previous recipe. Let's try this by launching our application by executing SPRING_CONFIG_LOCATION= file:/home/<username>/external.properties ./gradlew bootRun. We should see the following in the logs:
2017-12-17 --- ication$$EnhancerBySpringCGLIB$$b123df6a : Value of 
my.config.value property is: From Home Directory Config
While using environment variables is very convenient, it does have maintenance overhead if the number of these variables gets to be too many. To help deal with this issue, it is good practice to use a method of delegation by setting the SPRING_CONFIG_LOCATION variable to configure the location of the environment-specific properties file, typically by loading them from a URL location.
..................Content has been hidden....................

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