Skip to main content

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:

  1. Global configuration - this is configuration that is shared by multiple applications.
    • [base-directory]/global-config
  2. 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.

LocationDescription
System.getProperties()Properties from the environment
ks/global-config/common.propertiesCommon properties that are applicable to multiple applications
ks/global-config/local.propertiesCommon 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.propertiesCommon properties for the application
ks/[application]/config/local.propertiesCommon 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].propertiesApplication properties that can be overridden
ks/global-config/secrets.propertiesSecrets can be placed in this file in deployments
ks/global-config/override.propertiesOverrides can be placed in this file in deployments
note

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.