What is Spring boot 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
@EnableConfigServerannotation. Consequently, the following application is a config server
In Simple terms, Spring boot cloud config server takes your application.yml or application.properties from your spring boot application and serve it over HTTP, and spring application which need to use it just need to delete the application.yml or application.properties and create one bootstrap.yml/properties and defined 2 simple properties
- Create New java project using one of following instructions.
- Edit POM.xml, add following content in pom.xml
First specify the packaging
also add parent of this pom to be
NOTE: You can lookup the latest version for parent from here, I will advise to use latest version if possible at the time of writing this article its 2.0.4.RELEASE.
Add Rest of dependencies Right Click on Java folder and create new Java file com.next.config.SpringCloudConfigServer
NOTE : the annotation to enable config server
Add application.yml file in resources
Create Directory /tmp/config (if you are on Mac or Linux), on windows you can create directory like c:/tmp/config and update the application.yml with this path.
create a file application.yml in directory /tmp/config or c:/tmp/config
I am adding only one property for simplicity, but feel free to add as many as you like.
once file is created, initialise the git on this folder by running following commands.
Now the server is ready with minimum capabilities, that it can serve this application.yml from /tmp/config folder via http.
Start the server by right clicking on java file SpringCloudConfigServer and select Run,
once started visit http://localhost:8888/application/profile (basically url structure is http://localhost:8888/<application name>/<profile name(s)> and this will show you the content of /tmp/config/application.yml in format something like this
We have just seen simplest implementation of Spring Cloud Config server, this server doesn't care what application name or profile you passed to it, it will always return content of /tmp/config/application.yml which is not suitable for a production setup, as you may want to run multiple application in multiple environments(profiles).
I will explain such scenario in next section.