Setup and Configure Spring Cloud Config Server Project
Spring Cloud Config Server is just another Spring Boot application. It provides several infrastructure micro services to centralize access to configuration information backed by a version controlled (well at least in the case of default GIT storage) repository.
Step 1 - Create a Spring Boot project in STS with the dependencies shown in Figure 2.
|
Figure 2 - Spring Cloud Config Server dependencies |
The build.gradle file is shown in listing below. There is only one dependency to the Spring Cloud Config Server. Also Spring Cloud release train 'Dalston.SR1'.
Step 2 - Annotate the class containing main method
The next step is to annotate the ConfigServerInfraApplication class with @EnableConfigServer
That's all is needed on the Java side to start the configuration server.
Step 3 - Final step, create the configuration file.
Finally, create a file named bootstrap.yml and configure it as shown in listing below.
There are a few things to note in the configuration.
- The config server application has a name - 'config-service'
- The config server uses Github (public GIT repository) to store the configuration information.
- The configuration is actually stored in the folder 'config-store-infra' specified in the property 'search-paths'. This property actually specifies 'search-paths' a list of folders. For sake of simplicity, I have just configured one folder in this example. However, it is a good practice to use one folder per application/microservice.
- Note that the Git repository, it is possible to add username and password to provide secure access to the Github repository. But that too has been omitted here to keep the example simple. For more details, I would recommend reading the Spring Cloud config server documentation.
- The cofing server runs on port 8888
- The management or security on the config server is disabled.
Creating the config-store
The config server needs data in the Git(Github in this case) to share with the applications. So for that create a simple project in STS using the steps below.
1> Click on 'File' -> 'New' --> 'Project'.
2> In the New Project Wizard expand the node 'General' and select 'Project' (Figure 3) and click 'Next.'
Figure 3 - Select Project |
Figure 4 - Add project name and finish |
- lead-service-DEV.yml
- lead-service-STAGE.yml
- lead-service-PROD.yml
5> For testing purpose add a simple property in the lead-service-DEV.yml file.
6> Finally commit and push the config-store-infra project on Github repository.
The source code for this post is also available on Github location provided below.
Source Code
https://github.com/kdhrubo/playground
What's Next?
In the next post, I will show how to quickly test the Spring cloud config server using a browser. Then I will review the url patterns to be used for the Spring Cloud config server. I will then change the lead-backend microservice to use the config server.
Follow my blog with Bloglovin
Informative blog. Thanks for sharing.
ReplyDeleteMicroservices Online Training