#
Configuration Server
This tutorial explains how to create a Spring Cloud Config Server. This tutorial contains an example as well.
Spring Cloud Configuration Server loads the new configuration properties without restarting the application and without any downtime. This is the role of Spring Cloud Configuration Server.
First of all I will create a simple Spring Boot application using spring initializr as in the image below:
Now we need to add @EnableConfigServer
annotation to the main class of the application.
Now the main class will look like this:
package com.example.configserver;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
We need also to create a GitHub repo to keep the configuration file on it. We can also use local files for this purpose.
In order to connect to our GitHub repo, we need also to configure the ssh communication. More information we can get from here
In GitHub repo I will push the following files:
application.color.window=red
application.color.frame=white
application.color.car=blue
color.window=red
color.frame=white
color.car=blue
cloud.server.color.window=red
cloud.server.color.frame=white
cloud.server.color.car=blue
I will configure the application.properties for the Spring Cloud Config Server as below:
server.port=9900
spring.application.name=spring-cloud-config-server
spring.cloud.config.server.git.uri =git@github.com:catatomoiu/config.git
spring.cloud.config.server.git.clone-on-start=true
9900
: the port the Config Server is running on
spring-cloud-config-server
: the name of the Config Server
catatomoiu
: the name of the GitHub account
config
: the repository name
spring.cloud.config.server.git.clone-on-start=true
: each time the Config Server is starting, it takes the configurations from the
GitHub.
That's all.
Now we start the Config Server, and we put http://localhost:9900/spring-cloud-config-server/default
address in a browser.
In Firefox I can see the following :
Info
As you can see, both application.properties and spring-cloud-config-server.properties will be read by the Config Server. service-1.properties will not be read as the "service-1" is not the name of the Config Server.