Application Configuration
Purpose¶
A utility to manage application configuration.
Methods¶
Binding name: appconfig
Method: void save(String appKey, Map<String, Object> config)
Save the configuration defined in a key/value map.
The configuration is stored into a table AppConfig
attached to the application appKey
.
The table will automatically be created if it does not exist.
Each value is converted to its string representation before being saved. The following types are supported :
- String (default)
- Double
- Long
- Integer
- Float
- Boolean
- Byte
- UUID
- Date
- ZonedDateTime
- Character
If the type of the value does not match one of the previous types, the fallback conversion used will be
the String
.
Method: Object get(String appKey, String key)
Returns the configuration value
A B2boxException
exception will be throw if:
- the
AppConfig
table does not exist - there is no configuration entry for the specified key
Examples¶
Example 1
Save the initial configuration
appconfig.save("p6_demo", [ "description": "free text", "initialized": true, "version": 1 ])
Example 2
Read configuration
def description = appconfig.get("p6_demo", "description") boolean initialized = appconfig.get("p6_demo", "initialized")