How to configure Spring Cloud Config Server to Access a private GitHub repository
In this tutorial we are going to configure Spring Cloud Config Server so that it can connect to a remote GIT repository and fetch application properties to deliver it to our microservice applications.
Open application.properties file of our Spring cloud Config Server application created in our previous tutorial and add configurations as mentioned below.
spring.application.name=Springcloudconfigserver
server.port=8012
spring.cloud.config.server.git.uri=https://github.com/Deepak607398/behindjavalabs
spring.cloud.config.server.git.username=************
spring.cloud.config.server.git.password=**********
spring.cloud.config.server.git.clone-on-start=true
spring.cloud.config.server.git.clone-on-start
Flag to indicate that the repository should be cloned on startup (not on demand). Generally, leads to slower startup but faster first query.
Now go to the one of our micro service applications that we created in our previous tutorials and copy those properties into a file called application.properties and place it in the folder where we have cloned the git repository as follows.
cldee@DESKTOP-DR9500E MINGW64 /e/workspace/behindjavalabs (main)
$ git add .
cldee@DESKTOP-DR9500E MINGW64 /e/workspace/behindjavalabs (main)
$ git commit -m "Spring cloud config server test"
[main e49f2d6] Spring cloud config server test
1 file changed, 4 insertions(+)
create mode 100644 application.properties
cldee@DESKTOP-DR9500E MINGW64 /e/workspace/behindjavalabs (main)
$ git push
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 4 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 435 bytes | 435.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/Deepak607398/behindjavalabs.git
c4c1ad5..e49f2d6 main -> main
Now check the GitHub in web browser where you’ll find the application.properties with the changes committed as shown below.