This page has been migrated to github wiki: https://github.com/anotheria/configureme/wiki/Environments
ConfigureMe Environments
Definitions
Environments is the feature of the ConfigureMe, that gives possybility to predefine properties values for the different using situations.
Situations (actually, anything that have a common criteria) mean something like:
- Different servers
- Different users
- Different countries
- Different groups of users
- ...
Environments support any level cascading. The main cascading principles are:
- Property value from the lower level overrides property (same) value from the higher level.
- If requested environment not exists, values will be taken from the higher level environment (root is the default environment).
Example
This example covers all variants of environments using.
{ user: "defuser", mail: "defuser@anotheria.net", managers: { user: "managers", mail: "managers@anotheria.net", }, developers: { mail: "devs@anotheria.net", tom: { user: "tom", }, klark: { user: "klark", mail: "klark@anotheria.net", }, }, }
The table below shows what values we will have on what requested environment (levels are delimits by underline ('_') symbol).
Requested Environment | User Property Value | Mail Property Value |
---|---|---|
<empty> | defuser | defuser@anotheria.net |
unknownenv | defuser | defuser@anotheria.net |
unknownenv_subenv | defuser | defuser@anotheria.net |
managers | managers | managers@anotheria.net |
managers_bob | managers | managers@anotheria.net |
developers | defuser | devs@anotheria.net |
developers_tom | tom | devs@anotheria.net |
developers_klark | klark | klark@anotheria.net |
developers_bob | defuser | devs@anotheria.net |
Requesting environments
Set environment using system property
Configuration environment can be set on program running with the following command line parameter: "java -Dconfigureme.defaultEnvironment=<environment> ...".
Examples:
java -Dconfigureme.defaultEnvironment=developers ...
java -Dconfigureme.defaultEnvironment=developers_tom ...
java -Dconfigureme.defaultEnvironment=developers_tom_office ...
Set environment dynamically
Configuration environment can be set inside of program using the next code:
ConfigurationManager.INSTANCE.configure(EnvExampleConfig.getInstance(), "managers_tom"); String user = EnvExampleConfig.getInstance().getUser(); // user = "tom"