How to do it...

  1. Let's start by adding a bit of code to log the value of our particular configuration property so that we can easily see the change in it as we do different things. Add an @Bean method to the BookPubApplication class located in the src/main/java/org/test/bookpub directory at the root of our project with the following content:
@Bean 
public CommandLineRunner configValuePrinter(
@Value("${my.config.value:}") String configValue) { return args -> LogFactory.getLog(getClass()).
info("Value of my.config.value property is: " +
configValue); }
  1. Let's build the application by running ./gradlew clean bootJar and start it by running ./build/libs/bookpub-0.0.1-SNAPSHOT-exec.jar --spring.profiles.active=logger so as to see the following log output:
    2017-12-17 --- ication$$EnhancerBySpringCGLIB$$b123df6a : Value of 
my.config.value property is:
  1. The value is empty, as we expected. Next, we will create a file named external.properties in our home directly with the following content:
my.config.value=From Home Directory Config
  
  1. Let's run our application by executing ./build/libs/bookpub-0.0.1-SNAPSHOT-exec.jar --spring.profiles.active=logger --spring.config.location=file:/home/<username>/external.properties in order to see the following output in the logs:
2017-12-17 --- ication$$EnhancerBySpringCGLIB$$b123df6a : Value of my.config.value property is: From Home Directory Config
  
For macOS users, the home directories can be found in the /Users/<username> folder.
  1. We can also load the file as an HTTP resource and not from the local filesystem. So, place a file named external.properties with the content of my.config.value=From HTTP Config somewhere on the web. It can even be checked in a GitHub or BitBucket repository, as long as it is accessible without any need for authentication.
  2. Let's run our application by executing ./build/libs/bookpub-0.0.1-SNAPSHOT-exec.jar --spring.profiles.active=logger --spring.config.location=http://<your file location path>/external.properties in order to see the following output in the logs:
2017-12-17 --- ication$$EnhancerBySpringCGLIB$$b123df6a : Value of my.config.value property is: From HTTP Config
  
..................Content has been hidden....................

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