How to configure a Micro service to a be a client of Spring Cloud Config Server
In this tutorial we are going to configure a micro service that has been created in our previous tutorials as a client of the Spring cloud Config Server.
Now in the AccountMicroservice we created in our previous tutorial add the below metioned dependency into the pom.xml.
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bootstrap</artifactId> </dependency>
While working with spring boot and spring cloud projects we usually specify configuration details either in application.properties and application.yml files. But this time additionally to the already existing application properties file we will need to create a new bootstrap properties file.
So, this new file, bootstrap properties will be loaded before the application properties files loaded and it will be loaded even before the Java beans are created during the application startup.
To do this go to resources in account micro service and create a new properties files with the name bootstrap and add the following properties which makes the accountmircoservice to connect with the spring cloud config server.
Instead of creating a new properties file you can simple add the below configuration in the existing properties file.
Now run all the applications in order i.e., Eureka discovery service, API gateway, config server and finally our microservices and to test this comment all your properties in the application.properties present in your application and check the API’s.