Monday, 20 September 2021

Spring Cloud Config Server with Github

 1. Create a limit-service Client Spring Boot project from https://start.spring.io/


2. Create a spring-cloud-config-server Spring Boot project from https://start.spring.io/



3. Open application.properties in limits-service project and do two things;

spring.application.name=limits-service

server.port=8081


4. Open application.properties file in spring-cloud-config-server project.

spring.application.name=spring-cloud-config-server

server.port=8888


5. Open SpringCloudConfigServerApplication.java file in spring-cloud-config-server and include the below annotation there

@EnableConfigServer


6. Since Spring config server is starting at port 8888, we need to give the server address to limits-service. Add the below line in application.properties in limits-service project

spring.config.import=optional:configserver:http://localhost:8888


7. We can create a Local Git repo or Remote Git repo to add the properties files,

We need to give the path of properties files in application.properties of spring-cloud-config-server.


#Local Git config path

spring.cloud.config.server.git.uri=file:///D:/GitHub-Repo/git-localconfig-repo/


#Remote Git config path

spring.cloud.config.server.git.uri=https://github.com/amir35/git-config-repo


8. Remember the property file name should be same as that of microservice name.

Here microservice name is "limits-service". So properties name present at Git repo should be
"limits-service.properties"


9. Now you can start the limits-service server and you can see it will try to fetch data from spring-cloud-config-server which in turn will fetch data from limits-service.properties file from Git repo.


10. Now suppose you want to change any property from limits-service.properties file, you don't need to start server again for limits-service project.

Just you need to commit the files in Git repo and then execute one refresh endpoint.


11. Open application.properties file in limits-service and add below line:

management.endpoints.web.exposure.include=*

this will enable all the endpoints.

Then after making changes in the property file run this endpoint for changes to reflect on the microservice.

http://localhost:8081/actuator/refresh



Then execute the normal Rest endpoints as before and changes will reflect.


Source Code: Limits-service

No comments:

Post a Comment