Config Server is based on the open-source Spring Cloud Config Project, which provides a centralized server for configure application properties and central source for managing configuration across deployment environments.
How to implement Config Server in Spring Boot
Step 1: Create new Project For Config Server with the help of StartSpring and add given dependency in pom.xml file.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
Step 2: Go to main class and enable EnableDiscoveryClient and EnableConfigServer
@EnableConfigServer
@EnableDiscoveryClient
Step 3: Go to application.properties file and copy & paste given code
spring.application.name=CONFIG-SERVER
server.port=8888
eureka.client.service-url.default-zone=http://localhost:8761/eureka
## use git repository access
spring.cloud.config.server.git.uri=https://github.com/xxxxxx/config-server-testing
spring.cloud.config.server.git.default-label=main
spring.cloud.config.server.git.clone-on-start=true
** Create github account from https://github.com/login
Step 4: Add given dependency in Service 1(Customer Service) & Service 2(Employee Service)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
Step 5: Go to git repository and create property file but always remember properties file name is same as application name in small letter
EX:- application name:- CUSTOMER-SERVICE so properties file name is customer-service.properties
Step 6: Go to Service 1(Customer Service) properties file
Step 7: Copy all properties and Paste this properties in new properties file which you have created in git.
Step 8: Follow above 5,6,7 steps for Service 2(Employee Service).
Step 9: Now again go to your Service 1(Customer Service) application properties which is avialable in Service 1(Customer Service) and add given properties.
spring.application.name=CUSTOMER-SERVICE
## this is the config server url+port
spring.config.import=optional:configserver:http://localhost:8888
management.endpoints.web.exposure.include=*
Step 10: You can follow above step 9 for Service 2(Employee Service).
Step 11: Now you can restart your all services
That’s all.