blackjackyau / spring-config-file-based-auto-reloading

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Spring Config Auto Reloading solution for file-based configuration

It is almost impossible to hot reload the properties value from a native spring solution. For native java application, there's a solution from apache library (commons-configuration) but,

  • it is a different library from spring and low level (none declarative), not wise to give up spring config.
  • there's some example of integration link, but it is not as perfect (patchy)

Spring Cloud Config

  • Spring Cloud Config support config reloading via RefreshScope but not all integration type support automatic properties reload.
  • E.g. Spring Cloud Config Consul support but Spring Cloud Config Server doesn't.
  • RefreshScope is usually triggered via Spring Actuator Endpoint /actuator/refresh or via Spring Bus with queue system example

Project Introduction

  • In this project, we are using Spring Cloud Config of Embedding the Config Server with native file type boostrap.yml.
  • To support automatic reloading, we created a utility class to monitor the properties file. If the file changed is detected, a refresh scope event will be fired.
  • This integration will work in docker with the configuration folder is volume mounted, but it is not working with Kubernates ConfigMap volume mount.
  • Observation from testing, file from ConfigMap volume will only updated upon access (e.g. cat config file from terminal)
  • For ConfigMap integration, used Spring Config Kubernates Integration reference

Development Notes

Config search order is as such, it will look through config from all sources (appended effect) reference

file:./config/
file:./
classpath:/config/
classpath:/

About


Languages

Language:Java 97.5%Language:Dockerfile 2.5%