Storing Configuration as Key/Value Pairs
One way is to store the keys and values directly in Consul. In this case by default Micronaut looks for configuration in the Consul /config
directory.
You can alter the path searched for by setting consul.client.config.path |
Within the /config
directory Micronaut searches values within the following directories in order of precedence:
Directory | Description |
---|---|
| Configuration shared by all applications |
| Configuration shared by all applications for the |
| Application-specific configuration, example |
| Application-specific configuration for an active Environment |
The value of APPLICATION_NAME
is whatever your have configured micronaut.application.name
to be in bootstrap.yml
.
To see this in action, use the following cURL command to store a property called foo.bar
with a value of myvalue
in the directory /config/application
.
Using cURL to Write a Value
curl -X PUT -d @- localhost:8500/v1/kv/config/application/foo.bar <<< myvalue
If you now define a @Value("${foo.bar}")
or call environment.getProperty(..)
the value myvalue
will be resolved from Consul.