Externalize Application Configuration With Spring Cloud Config

Introduction

Spring Cloud Config

  • A server to provide the configuration
  • A client to fetch the configuration.

Spring Cloud Config Server

  • Spring Cloud Config Server
  • Git URL
  • AWS S3 bucket.
  • Redis
  • File System location.
  • HashiCorp Vault.
  • Cloudfoundary’s CredHub.

Configuring Spring Cloud Config with Git

server:
port: 8888
spring:
cloud:
config:
server:
git:
uri: https://github.com/amrutprabhu/spring-boot-external-configuration-options
http://localhost:8888/{client.application.name}/{profile}e.g
http://localhost:8888/config-client/dev

Customizing Config Location with Different Repositories

server:
port: 8888
spring:
cloud:
config:
server:
git:
uri: https://github.com/amrutprabhu/spring-boot-external-configuration-options
repos:

staging-properties-repo:
pattern : config-client/staging
uri:
https://github.com/amrutprabhu/spring-boot-external-configuration-options
search-paths:
- spring-cloud-config-server-setup/configs-location
config-client*/*
config-client/dev-*
config-*/dev*

Customizing Search patterns

  • {application} — to refer to the client’s application name.
  • {profile} — to refer to the client’s application profile.
prod-properies-repo:
uri: https://github.com/amrutprabhu/spring-boot-external-configuration-options
pattern: config-client/prod
search-paths:
- spring-cloud-config-server-setup/configs-location/{profile}

any-request-repo:
uri: https://github.com/amrutprabhu/spring-boot-external-configuration-options
pattern: config-client*/*
search-paths:
- spring-cloud-config-server-setup/configs-location/{application}/{profile}

Creating Spring Cloud Config Client.

  • Spring Cloud Starter Config
  • Spring Boot Web Starter (required only for tomcat server)
spring:
application:
name: config-client
config:
import: "configserver:"
spring:
cloud:
config:
uri: http://localhost:8888
java -jar target/config-client-service-0.0.1-SNAPSHOT.jar \                                                     --spring.profiles.active=prod

Useful Tip.

prod-properies-repo:
uri: file:///home/user/
spring-boot-external-configuration-options
pattern: config-client/prod
search-paths:
- spring-cloud-config-server-setup/configs-location/{profile}

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Amrut Prabhu

Amrut Prabhu

Software Craftsman, Tech Enthusiast. I run https://refactorfirst.com to post all my articles