(Quick Reference)

5.3 Runtime Configuration - Reference Documentation

Authors: Andres Almiray

Version: 1.2.0

5.3 Runtime Configuration

The application's runtime configuration is available through the config property of the application instance. This is a ConfigObject whose contents are obtained by merging Application.groovy and Config.groovy. Builder configuration is available through the builderConfig property and reflects the contents of Builder.groovy. Configuration files may also be provided as properties files; settings on the matching script will be overridden by those set in the properties file.

5.3.1 Internationalization Support

Configuration files are i18n aware which means you can append locale specific strings to a configuration file, for example Config_de_CH.groovy. Locale suffixes are resolved from least to most specific; for a locale with language = 'de', country = 'CH' and variant = 'Basel' the following files are loaded in order
  • Config.groovy
  • Config.properties
  • Config_de.groovy
  • Config_de.properties
  • Config_de_CH.groovy
  • Config_de_CH.properties
  • Config_de_CH_Basel.groovy
  • Config_de_CH_Basel.properties

By default the current Locale is used to determine values for language, country and variant; you can change this value by tweaking the application's locale.

5.3.2 External Configuration Support

Some deployments require that configuration be sourced from more than one place and be changeable without requiring a rebuild of the application. In order to support deployment scenarios such as these the configuration can be externalized. To do so, point Griffon at the locations of the configuration files that should be used by adding a griffon.config.locations setting in Config.groovy, for example:

griffon.config.locations = [
    "classpath:${appName}-config.properties",
    "classpath:${appName}-config.groovy",
    "file:${userHome}/.griffon/${appName}-config.properties",
    "file:${userHome}/.griffon/${appName}-config.groovy"]

In the above example we're loading configuration files (both Java Properties files and ConfigReader configurations) from different places on the classpath and files located in USER_HOME.

It is also possible to load config by specifying a class that is a config script.

griffon.config.locations = [com.my.app.MyConfig]

This can be useful in situations where the config is either coming from a plugin or some other part of your application. A typical use for this is re-using configuration provided by plugins across multiple applications.

Ultimately all configuration files get merged into the config property of the GriffonApplication object and are hence obtainable from there.

Values that have the same name as previously defined values will overwrite the existing values, and the pointed to configuration sources are loaded in the order in which they are defined.