Config
Class
trading.keysquare.config.Config
Singleton class that provides access to configuration found in properties files. Properties files are loaded when the first instance of Config is obtained using getInstance().
There are two locations in which configuration is sourced:
- Global configuration - this is configuration that is shared by multiple applications.
- [base-directory]/global-config
- Application configuration - this is configuration that is specific to an application.
- [base-directory]/[application]/config
The order in which properties are sourced is as follows, note that each of these files is optional and therefore only those needed can be defined.
| Location | Description |
|---|---|
| System.getProperties() | Properties from the environment |
| ks/global-config/common.properties | Common properties that are applicable to multiple applications |
| ks/global-config/local.properties | Common properties that are applicable to multiple applications - this is available for local development purposes, where values that shouldn't be placed in source control should be added |
| ks/[application]/config/common.properties | Common properties for the application |
| ks/[application]/config/local.properties | Common propertoes for the application - this is available for local development purposes, where values that shouldn't be placed in source control should be added |
| ks/global-config/[application].properties | Application properties that can be overridden |
| ks/global-config/secrets.properties | Secrets can be placed in this file in deployments |
| ks/global-config/override.properties | Overrides can be placed in this file in deployments |
Note that if a property is defined in a later file, then the later value will override the earlier value.
An instance of Config can be obtained by using the getInstance() method:
Config config = Config.getInstance();
Methods
String get(String key)
Returns a configuration property as a String.
int getInt(String key)
Returns a configuration property as an int.
long getLong(String key)
Returns a configuration property as a long.
boolean getBoolean(String key)
Returns a configuration property as a boolean.
Class<T> getClass(String key)
Return a configuration property as a Class.
T getClassInstance(String key)
Return a configuration property as an instance of a Class.
T getEnum(Class<T> enumType, String key)
A configuration property as an Enum. The Enum type is passed in as a parameter to the method.
String> getConfig()
Returns all configuration.
boolean containsKey(String key)
Returns a boolean indicating if the configuration key is defined.
String getEnvironment()
Returns the environment.
String getApplicationName()
Returns the application name.
Config getInstance()
Returns the singleton instance of Config.