public class Config
extends java.lang.Object
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:
For example:
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.
| Modifier and Type | Method and Description |
|---|---|
static void |
clearConfiguration()
Nulls out the system wide CompositeConfiguration, same as
setConfiguration(null) |
protected static java.net.URL |
findUrl(java.lang.String name)
Attempts to locate a resource URL for
name via the ClassLoader or as a file path relative to ${user.dir}. |
static java.math.BigDecimal |
getBigDecimal(java.lang.String key) |
static java.math.BigDecimal |
getBigDecimal(java.lang.String key,
java.math.BigDecimal defaultValue) |
static java.math.BigInteger |
getBigInteger(java.lang.String key) |
static java.math.BigInteger |
getBigInteger(java.lang.String key,
java.math.BigInteger defaultValue) |
static boolean |
getBoolean(java.lang.String key) |
static boolean |
getBoolean(java.lang.String key,
boolean defaultValue) |
static java.lang.Boolean |
getBoolean(java.lang.String key,
java.lang.Boolean defaultValue) |
static byte |
getByte(java.lang.String key) |
static byte |
getByte(java.lang.String key,
byte defaultValue) |
static java.lang.Byte |
getByte(java.lang.String key,
java.lang.Byte defaultValue) |
static org.apache.commons.configuration2.CompositeConfiguration |
getConfiguration()
If
configuration is null, loadConfiguration is called
to lazy load the default config. |
static double |
getDouble(java.lang.String key) |
static double |
getDouble(java.lang.String key,
double defaultValue) |
static java.lang.Double |
getDouble(java.lang.String key,
java.lang.Double defaultValue) |
static float |
getFloat(java.lang.String key) |
static float |
getFloat(java.lang.String key,
float defaultValue) |
static java.lang.Float |
getFloat(java.lang.String key,
java.lang.Float defaultValue) |
static int |
getInt(java.lang.String key) |
static int |
getInt(java.lang.String key,
int defaultValue) |
static java.lang.Integer |
getInteger(java.lang.String key,
java.lang.Integer defaultValue) |
static java.util.Iterator<java.lang.String> |
getKeys() |
static long |
getLong(java.lang.String key) |
static long |
getLong(java.lang.String key,
long defaultValue) |
static java.lang.Long |
getLong(java.lang.String key,
java.lang.Long defaultValue) |
static java.lang.Object |
getProperty(java.lang.String key) |
static short |
getShort(java.lang.String key) |
static short |
getShort(java.lang.String key,
short defaultValue) |
static java.lang.Short |
getShort(java.lang.String key,
java.lang.Short defaultValue) |
static java.lang.String |
getString(java.lang.String key) |
static java.lang.String |
getString(java.lang.String key,
java.lang.String defaultValue) |
static boolean |
hasConfiguration() |
static void |
loadConfiguration(java.lang.String configPath,
java.lang.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 void |
setConfiguration(org.apache.commons.configuration2.CompositeConfiguration configuration)
Sets the system wide CompositeConfiguration.
|
public static boolean hasConfiguration()
public static org.apache.commons.configuration2.CompositeConfiguration getConfiguration()
configuration is null, loadConfiguration is called
to lazy load the default config.public static void setConfiguration(org.apache.commons.configuration2.CompositeConfiguration configuration)
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()
if configuration is null.
configuration - the configuration to usepublic static void clearConfiguration()
setConfiguration(null)public static void loadConfiguration(java.lang.String configPath,
java.lang.String configProfile)
If configPath is null, it will be looked up via Utils.findProperty with the following keys:
If configProfile is null, it will be looked up via Utils.findProperty with the following keys:
configPath - the path use to locate 'inversion.properties' files via getResourceconfigProfile - the runtime profile used to load some inversion-${configProfile}-[0-100].properties files and not others.findUrl(String),
Utils.findSysEnvProp(String...)protected static java.net.URL findUrl(java.lang.String name)
name via the ClassLoader or as a file path relative to ${user.dir}.name - a string identifier for the resource to findpublic static java.util.Iterator<java.lang.String> getKeys()
public static java.lang.Object getProperty(java.lang.String key)
public static boolean getBoolean(java.lang.String key)
public static boolean getBoolean(java.lang.String key,
boolean defaultValue)
public static java.lang.Boolean getBoolean(java.lang.String key,
java.lang.Boolean defaultValue)
public static byte getByte(java.lang.String key)
public static byte getByte(java.lang.String key,
byte defaultValue)
public static java.lang.Byte getByte(java.lang.String key,
java.lang.Byte defaultValue)
public static double getDouble(java.lang.String key)
public static double getDouble(java.lang.String key,
double defaultValue)
public static java.lang.Double getDouble(java.lang.String key,
java.lang.Double defaultValue)
public static float getFloat(java.lang.String key)
public static float getFloat(java.lang.String key,
float defaultValue)
public static java.lang.Float getFloat(java.lang.String key,
java.lang.Float defaultValue)
public static int getInt(java.lang.String key)
public static int getInt(java.lang.String key,
int defaultValue)
public static java.lang.Integer getInteger(java.lang.String key,
java.lang.Integer defaultValue)
public static long getLong(java.lang.String key)
public static long getLong(java.lang.String key,
long defaultValue)
public static java.lang.Long getLong(java.lang.String key,
java.lang.Long defaultValue)
public static short getShort(java.lang.String key)
public static short getShort(java.lang.String key,
short defaultValue)
public static java.lang.Short getShort(java.lang.String key,
java.lang.Short defaultValue)
public static java.math.BigDecimal getBigDecimal(java.lang.String key)
public static java.math.BigDecimal getBigDecimal(java.lang.String key,
java.math.BigDecimal defaultValue)
public static java.math.BigInteger getBigInteger(java.lang.String key)
public static java.math.BigInteger getBigInteger(java.lang.String key,
java.math.BigInteger defaultValue)
public static java.lang.String getString(java.lang.String key)
public static java.lang.String getString(java.lang.String key,
java.lang.String defaultValue)
Copyright © 2021 Rocket Partners, LLC. All rights reserved.