Skip to content

Instantly share code, notes, and snippets.

@vipulkumarsviit
Last active November 19, 2021 12:29
Show Gist options
  • Save vipulkumarsviit/45d820e70d9b9d596ca429e6efbc657f to your computer and use it in GitHub Desktop.
Save vipulkumarsviit/45d820e70d9b9d596ca429e6efbc657f to your computer and use it in GitHub Desktop.
How to read config from file system or classpath or git location in spring boot application

Step 1: Create an application from https://start.spring.io with a dependency of spring-cloud-config-server.

Setp 2: Annotate your main application class with @EnableConfigServer

Step 3: Add below properties in application.properties

#Uncomment below section to use git as config location
spring.profiles.active=git
spring.cloud.config.server.git.uri=https://github.com/awesome-bank/awesome-bank-config.git
spring.cloud.config.server.git.clone-on-start=true
spring.cloud.config.server.git.default-label=main

#Uncomment below section to use project classpath as config location
#spring.profiles.active=native
#spring.cloud.config.server.native.search-locations=classpath:/configs

#Uncomment below section to use system path as config location
#spring.profiles.active=native
#spring.cloud.config.server.native.search-locations=file:///C:/code/bank/config-server/src/main/resources/configs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment