Class Config
The name/value pairs found in configuration are used by the Configurator to reflectively set bean properties on Apis, Endpoints, Actions, Dbs and other Api model objects during Engine startup.
Automatic/reflective parameter setting via the Configurator is the preferred way to do runtime dependency injection. You can however directly use this classes Config.getXYX() methods to look up key/value pairs at runtime.
You can access and modify the underlying CompositeConfiguration object to change where properties are pulled form.
By default, listed in order of priority, properties are merged from:
- a "${user.dir}/.env" properties file if one exists.
- system properties
- environment variables
- ${configPath}/inversion[-][0-100]-${configProfile}.properties files if they exist
- ${configPath}/inversion-${configProfile}[-][0-100].properties files if they exist
- ${configPath}/inversion[-][0-100].properties files if they exist
For example:
- if key "foo" is found in "${user.dir}/.env" the corresponding value will always be returned no matter what other source have key "foo"
- if key "bar" exists in inversion-${configProfile}.properties and inversion.properties, the value from inversion-${configProfile}.properties will be returned
- if key "abc" is environment and inversion-${configProfile}.properties, the value from the environment will be returned
- if key "xyz" is in inversion.properties and inversion-10.properties, the value from inversion-10.properties will be returned
If you have a custom configuration data source, such as a database or secrets key vault, you can add those to the FRONT of the
CompositeConfiguration via Config.getConfiguration().addConfigurationFirst(MY_CONFIG_OBJECT) to make sure those values
are given the highest priority. Use CompositeConfiguration.addConfiguration to give your custom props lowest priority.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidNulls out the system wide CompositeConfiguration, same assetConfiguration(null)protected static URLAttempts to locate a resource URL fornamevia the ClassLoader or as a file path relative to ${user.dir}.static BigDecimalgetBigDecimal(String key) static BigDecimalgetBigDecimal(String key, BigDecimal defaultValue) static BigIntegergetBigInteger(String key) static BigIntegergetBigInteger(String key, BigInteger defaultValue) static booleangetBoolean(String key) static booleangetBoolean(String key, boolean defaultValue) static BooleangetBoolean(String key, Boolean defaultValue) static bytestatic bytestatic Bytestatic org.apache.commons.configuration2.CompositeConfigurationIfconfigurationis null,loadConfigurationis called to lazy load the default config.static doublestatic doublestatic Doublestatic floatstatic floatstatic Floatstatic intstatic intstatic IntegergetInteger(String key, Integer defaultValue) getKeys()static longstatic longstatic Longstatic ObjectgetProperty(String key) static shortstatic shortstatic Shortstatic Stringstatic Stringstatic booleanstatic voidloadConfiguration(String configPath, String configProfile) Creates a new CompositeConfiguration with individual Configuration objects loaded with key/value pairs from sources as described in the class comment above.static voidsetConfiguration(org.apache.commons.configuration2.CompositeConfiguration configuration) Sets the system wide CompositeConfiguration.
-
Method Details
-
hasConfiguration
public static boolean hasConfiguration() -
getConfiguration
public static org.apache.commons.configuration2.CompositeConfiguration getConfiguration()Ifconfigurationis null,loadConfigurationis called to lazy load the default config.- Returns:
- the system wide CompositeConfiguration
-
setConfiguration
public static void setConfiguration(org.apache.commons.configuration2.CompositeConfiguration configuration) Sets the system wide CompositeConfiguration.Generally, you don't need to explicitly call this, as accessing any of this classes getters will cause the default configuration to be loaded via
loadConfiguration()ifconfigurationis null.- Parameters:
configuration- the configuration to use
-
clearConfiguration
public static void clearConfiguration()Nulls out the system wide CompositeConfiguration, same assetConfiguration(null) -
loadConfiguration
Creates a new CompositeConfiguration with individual Configuration objects loaded with key/value pairs from sources as described in the class comment above.If
configPathis null, it will be looked up via Utils.findProperty with the following keys:- "inversion.configPath"
- "configPath"
If
configProfileis null, it will be looked up via Utils.findProperty with the following keys:- "inversion.configProfile"
- "inversion.profile"
- "spring.profiles.active"
- "configProfile"
- "profile"
- Parameters:
configPath- the path use to locate 'inversion.properties' files viagetResourceconfigProfile- the runtime profile used to load some inversion-${configProfile}-[0-100].properties files and not others.- See Also:
-
findUrl
Attempts to locate a resource URL fornamevia the ClassLoader or as a file path relative to ${user.dir}.- Parameters:
name- a string identifier for the resource to find- Returns:
- a url
-
getKeys
-
getProperty
-
getBoolean
-
getBoolean
-
getBoolean
-
getByte
-
getByte
-
getByte
-
getDouble
-
getDouble
-
getDouble
-
getFloat
-
getFloat
-
getFloat
-
getInt
-
getInt
-
getInteger
-
getLong
-
getLong
-
getLong
-
getShort
-
getShort
-
getShort
-
getBigDecimal
-
getBigDecimal
-
getBigInteger
-
getBigInteger
-
getString
-
getString
-