Skip to main content

How to Stand up a Spring Cloud Config Server?


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 1 - Creating Spring Boot project to setup Spring Cloud Config Server


Figure 2 - Spring Cloud Config Server dependencies
Click on 'Finish' to complete the creation of the Spring Boot project in STS.
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. 
Now run the ConfigServerInfraApplication class as a Spring Boot application from STS and it should start the Spring Cloud Config Server.

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

3>  In the New Project dialog, type the name of the project and click on 'Finish'.


Figure 4 - Add project name and finish
4> Create three different files for different environments (development, staging, and production) as follows

  • 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

Comments

Post a Comment

Popular posts from this blog

CKEDITOR 3.x - Simplest Ajax Submit Plugin

  I have assumed that you have downloaded and got started with CKEDITOR. Step 1 – The html file is shown below: <html> <head> <title>Writer</title> <meta content="text/html; charset=utf-8" http-equiv="content-type" /> <script type="text/javascript" src="ckeditor/ckeditor.js"></script> <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script> <style> .cke_contents { height: 400px !important; } </style> </head> <body> <form action="sample_posteddata.php" method="post"> <textarea id="editor" > </textarea> <script type="text/javascript"> //<![CDATA[ CKEDITOR.replace( 'editor', { fullPage : true, uiColor : '#9AB8F3', toolbar : 'MyToolbar' }); //]]> </script> </form> </body> </html> Note that the jquery js

Part 3 - Integrating Tiles, Thymeleaf and Spring MVC 3

In this post I will demonstrate how to integrate Apache Tiles with Thymeleaf. This is very simple. The first step is to include the tiles and thymeleaf-tiles extension dependencies. I will include them in the pom.xml. Note we wil lbe using Tiles 2.2.2 Listing 1 - parent/pom.xml --- thymeleaf-tiles and tiles dependencies <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <!-- Tiles --> <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <dependency> <groupId>org.apache.tiles</groupId> <artifactId>tiles-core</artifactId> <version>${tiles.version}</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.tiles</groupId> <artifactId>tiles-template</artifactId> <version>${tiles.version}</version> <scope>compile</s