Spring Cloud Config
Spring Cloud provides tools for developers to quickly build some of the common patterns in distributed systems (e.g. configuration management, service discovery, circuit breakers, intelligent routing, micro-proxy, control bus).
Distributed/Versioned Configuration
Spring cloud config
Spring Cloud Config provides server-side and client-side support for externalized configuration in a distributed system. With the Config Server, you have a central place to manage external properties for applications across all environments.
Under spring cloud config the focus is on two areas:
- ) Spring Cloud Config Server
Spring Cloud Config Server provides an HTTP resource-based API for external configuration (name-value pairs or equivalent YAML content). The server is embeddable in a Spring Boot application, by using the @EnableConfigServer annotation.
The main maven dependencies used:
- Config Server (Spring cloud config)
- Spring configuration Processor (Developer tools) — gives intellicense for spring boot
Create a project from Spring Initializr and then add the above dependencies
At the main spring boot entry file add the following annotation
Next, in the application.properties file under recourse directory:
In my case I prefer renaming the properties file to yml file
You create a new repository to store the configuration properties with application.yml file in the folder where the git is initialized, then import the configurations using the above syntax in the image:
Get Master Musili’s stories in your inbox
Join Medium for free to get updates from this writer.
They can either be imported using:
- From github uri — (Remote if its pushed to github)
- Path to local files in your computer (As show in the above image)
Finally you can run your config server and confirm whether its running through the following url:
https://localhost/8888/application/default
2.) Spring Cloud Config Client
Now that we have the config server app, we can now enable our services to listen to configurations from the config server
Spring Boot Config Data Import
Spring Boot 2.4 introduced a new way to import configuration data via the spring.config.import property. This is now the default way to bind to Config Server.
To optionally connect to config server set the following in application.properties:
The config-import imports the port where config server is running, and reads the configurations
N/B
For the configurations to imported from external repo and enable communication, the properties file in the external repo name must be the same to the name of your service — spring.application.name: “Name of your service” — the flag is in your service properties file.
For the common properties they are stored in the application properties files in the external repo, while properties for each specific service you create the properties file for the specific service
Dependencies:
Config Client — Spring cloud config
For the service to run ensure:
The import syantax in the service properties file is available as indicated in the above image
The optional keyword
Implies that it does not need the config service to be up for it to run, it can run independently
To avoid conflicts of ports with other services always ensure the config service is running, so that the other services can import configurations
For more insights you can visit the spring documentation
Happy Coding!









