Nesting Configurations
Coat allows embedding config objects in other config objects.
It is helpful in the case when parts of a configuration are reused in multiple other configurations without having to duplicate all the accessor methods of the embedded config class.
Example
As an example see the following MqttConfig
that is embedded in the main
AppConfig
.
1@Coat.Config
2public interface MqttConfig {
3
4 @Coat.Param(key = "client_id")
5 public Optional<String> clientId();
6
7 @Coat.Param(key = "broker_address")
8 public InetAddress brokerAddress();
9
10 @Coat.Param(key = "port", defaultValue = "1883")
11 public int port();
1@Coat.Config
2public interface AppConfig {
3
4 @Coat.Param(key = "name")
5 public String name();
6
7 @Coat.Embedded(key = "mqtt")
8 public MqttConfig mqtt();
A config file for that configuration would look like this:
1name = …
2mqtt.client_id = …
3mqtt.broker_address = …
4mqtt.port = …
The config keys of the embedded config get a common prefix that is
specified on the @Coat.Embedded
annotation of its accessor method. By
default that prefix is separated from the actual config key via a single
dot.