TOML Config Source
The TOML Config Source takes configuration properties from a TOML configuration file.
Configuration in Payara Server
You can configure TOML Config Source either via the admin console or the asadmin utility.
You’ll need the path of the TOML configuration file and the maximum recursion depth.
From the Admin Console
To configure the config source from the admin console, go to Configs
→ your-config
→ MicroProfile
→ Config
→ TOML
.
From here you can enter the path to the TOML configuration file and set the maximum recursion depth.
You can also decide whether to apply these changes dynamically or on the next server restart. If the config source is enabled or disabled dynamically it will take effect across the server immediately.
From the Command Line
To configure the TOML Config Source from the command line, use these commands:
set-toml-config-source-configuration
Configures the toml configuration source.
Usage
asadmin set-toml-config-source-configuration
[--path=<path>]
[--depth=<depth>]
[--dynamic={true|false}]
[--enabled={true|false}]
[--target=<target[default:server]>]
The set-toml-config-source-configuration
provides configuration options to set the properties required by TOML config source to read the values from the configured file.
Configuration Options
Option | Type | Description | Default | Mandatory |
---|---|---|---|---|
|
|
Absolute path of the TOML file or relative path to the current domain. |
Yes |
|
|
|
Maximum recursion depth for nested tables/arrays. |
Yes |
|
|
|
Configure the config source dynamically, which will not require a restart. |
|
No |
|
|
Enables or disables the config source. |
|
No |
|
|
Specifies the target where the configuration source resides. |
|
No |
Usage
Provided that all of the above sections are configured correctly, the properties can be injected into any applicable MicroProfile Config injection point as with any other Config Source. They can also be fetched using the asadmin utility.
To prevent StackOverFlowException
issues, the depth
parameter limits the recursion depth when reading properties from the TOML file. If the maximum recursion depth is reached, further properties will not be read.
Examples
title = "TOML Example"
[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00
[database]
enabled = true
ports = [ 8000, 8001, 8002 ]
Config config = ConfigProvider.getConfig();
String ownerName = config.getValue("owner.name", String.class);
@Inject
@ConfigProperty(name="database.ports[0]")
private Optional<Integer> databasePort;