spring - (Too) complex configuration management (Java properties) -
i'm working @ company having (too) complex configuration management process:
- in each module there application.properties file. there properties developers like:
database.host = localhost
- properties change in other environments maintained in application.properties file in override-properties folder (for each module) like:
database.host=@dbhost@
- there default-deployment.properties file default values other environments like: database.host=novalueconfigured.db_host
- a postconfigure.properties file
database_ host=@configure.db_host@
those files needed if property value depends on environments (is different development, testing, live).
- finally there excel document sheet every environment , row like:
configure.db_host
-a comment ...
-127.0.0.1
(just example). excel responsible generating correct property files rpm packages.
this process not complex error prone. how simplified/improved?
the approach should compatbiel spring di.
i start master configuration file , generate properties files start with.
ultimately have set of proprties files can deployed in environments e.g.
database.host = localhost database.host.prod = proddb1 database.host.uat = uatdb1
i.e. use environment/host/region/service @ end search path. has advantage can see variations between environments.
you can implement collect this
public class searchproperties extends properties { private final list<string> searchlist; public searchproperties(list<string> searchlist) { this.searchlist = searchlist; } @override public string getproperty(string key) { (string s : searchlist) { string property = super.getproperty(key + "." + s); if (property != null) return property; } return super.getproperty(key); }
you might construct like
properties prop = new searchproperties(arrays.aslist(servername, environment));
this way, if there match server, override, environment overidden default.
in java 8 can do
public string getproperty(string key) { return searchlist.stream() .map(s -> key + "." + s) .map(super::getproperty) .filter(s -> s != null) .findfirst() .orelseget(()-> super.getproperty(key)); }
Comments
Post a Comment