We will start by enhancing our BookPub project with base Spring Cloud modules by adding them to the main build configuration:
- 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") ... }
- Start the application by running ./gradlew clean bootRun
- 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" } } }
- 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
- Start the application by running ./gradlew clean bootRun
- 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" } } }