Skip to content

jramsden/yamlconfig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

yamlconfig

Java Application Configuration

Retrieving settings from configuration:

configurations:
  -
    namespace: ramsdenj
    keys:
      sampleKey: sampleValue
      sampleKeyMap:
        nestedKeyOne: nestedValueOne
        nestedKeyTwo: nestedValueTwo
  -
    namespace: ramsdenj.myappgroup.myapp
    keys:
      sampleKey: sampleValueOverride
  -
    namespace: ramsdenj.myappgroup.myapp.dev.us-east-1
    keys:
      sampleKeyTwo: sampleValueTwo
YamlConfig yamlConfig = new YamlConfigImpl("ramsdenj", configurationInstanceProvider);
yamlConfig.getSetting("sampleKey");                     // returns "sampleValue"
yamlConfig.getSetting("sampleKeyMap->nestedKeyOne")     // returns "nestedValueOne"
YamlConfig yamlConfig = new YamlConfigImpl("ramsdenj.myappgroup.myapp", configurationInstanceProvider);
yamlConfig.getSetting("sampleKey");     // returns "sampleValueOverride"
yamlConfig.getSetting("sampleKeyTwo");  // throws ConfigurationKeyNotFoundException

You can also retrieve POJOs:

configurations:
  -
    namespace: ramsdenj
    keys:
      point:
        x: 1.0
        y: 2.2
YamlConfig yamlConfig = new YamlConfigImpl("ramsdenj.myappgroup.myapp.dev", configurationInstanceProvider);
yamlConfig.getSetting("point", Point.class);            // returns an instance of Point.

You should never define the same key in the same scope more than once. If the same key is defined more than once in the same scope, the key will be overwritten so the last key encountered will be the one taken. Since the order configuration is read is not guaranteed, this will result in non-deterministic behavior.

About

Java Yaml Application Configuration

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages