Class Config
- All Implemented Interfaces:
Map,org.apache.commons.collections4.Get,org.apache.commons.collections4.IterableGet,org.apache.commons.collections4.IterableMap,org.apache.commons.collections4.Put
If running in a servlets environment, you must use the "Init" servlet and use <load-on-startup> to ensure it initializes before any calls are made to this class.
Then the Config class can be used to read settings as follows:
Config config = Config.getGlobal();
String propertyValue = (String)config.getProperty("propertyName");
If running outside of a servlet environment, the following call should be made from the startup thread of the application before any Config APIs are called:
Config.initGlobalConfig();
-
Method Summary
Modifier and TypeMethodDescriptionstatic ConfigReturns the global Config object, initializing it if it has not yet been set up.static ConfiggetGlobal(boolean initIfNull) Returns the global Config object, optionally initializing it if it has not yet been set up.static ObjectgetProperty(String propertyName) Returns a property extracted from the SmartClient global configuration file, server.properties.static ConfigInitializes the global Config using the default Isomorphic ConfigLoader and ConfigParser, which read.propertiesfiles with variable interpolation.static booleanIs the application running as a Spring Boot app? You can configure this explicitly by setting "is.spring.boot.app" to true in you server.properties file.Programmatically inject a value into the global config.voidProgrammatically inject a set of values in a Map into the global config.
-
Method Details
-
getGlobal
Returns the global Config object, optionally initializing it if it has not yet been set up.In a servlet environment, the Init servlet handles initialization automatically. In a non-servlet environment, call
initGlobalConfig()from the startup thread before calling this method.- Parameters:
initIfNull- if true, automatically callsinitGlobalConfig()when the global config has not yet been initialized- Returns:
- the global Config instance, or null if
initIfNullis false and the config has not been initialized
-
getGlobal
Returns the global Config object, initializing it if it has not yet been set up. Equivalent to callinggetGlobal(true).See the
class overviewfor usage examples.- Returns:
- the global Config instance
-
getProperty
Returns a property extracted from the SmartClient global configuration file, server.properties. Note that the Init servlet must be used if you wish to make use of this API.- Parameters:
propertyName- The name of the property to retrieve- Returns:
- The property value, or null if it was not found
-
initGlobalConfig
Initializes the global Config using the default Isomorphic ConfigLoader and ConfigParser, which read.propertiesfiles with variable interpolation.In a servlet environment, the Init servlet calls this automatically. In a non-servlet environment, call this from the startup thread before any Config APIs are used, as shown in the
class overview.- Returns:
- the initialized global Config instance
- Throws:
Exception- if the configuration cannot be loaded
-
put
Programmatically inject a value into the global config. Note, the timing of this is key. Your programmatic overrides or additions must take place after the core config has loaded from the framework's various.propertiesfiles, but before anything else in the system.The simplest way to achieve this is to have your programmatic changes to config invoked from a servlet which is configured in
web.xmlwith aload-on-startupparameter of 2, like this:<servlet> <servlet-name>MyConfigChanges</servlet-name> <servlet-class>com.company.servlet.MyConfigChanges</servlet-class> <load-on-startup>2</load-on-startup> </servlet>The setting of "2" is important, because your code needs to run after the SmartClientInitservlet, but before anything else.If running outside of a servlet environment, you should invoke your config override code from the startup thread of the application, after the call to
Config.initGlobalConfig()described in the class overview docs, but before any Config APIs are called.- Parameters:
key- The key of the property to setvalue- The new value for the property- Returns:
- The property's old value, or null if it was not previously set
-
putAll
Programmatically inject a set of values in a Map into the global config. Seeput(Object, Object)for important information about timing issues associated with this API.- Parameters:
map- A Map of property values to apply to the config
-
isSpringBootApp
public static boolean isSpringBootApp()Is the application running as a Spring Boot app? You can configure this explicitly by setting "is.spring.boot.app" to true in you server.properties file. Absent that setting, we assume a Spring Boot app if the standard "org.springframework.boot.SpringApplication" class is present - but note that this class can legitimately be present in a non-Boot app, so it is better to use the explicit setting if possible- Returns:
- true if the application is configured (or appears) to be a Spring Boot app
-