How to do it...

We will start by enhancing our BookPub project with base Spring Cloud modules by adding them to the main build configuration:

  1. Add the following content to the build.gradle file located at the root of the project:
... 
apply plugin: 'docker' 
 
dependencyManagement { 
    imports { 
        mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Finchley.BUILD-SNAPSHOT' 
    } 
} 
 
jar { 
    baseName = 'bookpub' 
    version = '0.0.1-SNAPSHOT' 
} 
 
... 
 
dependencies { 
    ... 
    compile("org.springframework.boot:spring-boot-devtools") 
    compile("org.springframework.cloud:spring-cloud-context") 
    compile("org.springframework.cloud:spring-cloud-commons") 
    runtime("com.h2database:h2") 
    ... 
}
  1. Start the application by running ./gradlew clean bootRun
  2. After the application has been started, even though it seems like nothing new has happened, if we open our browser at http://localhost:8081/actuator/env (the management endpoint for environment), we will see new property sources appear:
{ 
  "name": "springCloudClientHostInfo", 
  "properties": { 
    "spring.cloud.client.hostname": { 
      "value": "127.0.0.1" 
    }, 
    "spring.cloud.client.ip-address": { 
      "value": "127.0.0.1" 
    } 
  } 
} 
  1. Create a bootstrap.properties file under the src/main/resources directory from the root of our project with the following content (the same properties should be commented out inside application.properties at this point):
spring.application.name=BookPub-ch9 
  1. Start the application by running ./gradlew clean bootRun
  2. After the application has been started, open our browser at http://localhost:8081/env and we will see new property sources appear:
{ 
  "name": "applicationConfig: [classpath:/bootstrap.properties]", 
  "properties": { 
    "spring.application.name": { 
      "value": "BookPub-ch9", 
      "origin": "class path resource [bootstrap.properties]:1:25" 
    } 
  } 
}
..................Content has been hidden....................

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