Storing Configuration as Key/Value Pairs

One way is to store each key and value directly in Consul. In this case by default Micronaut will look for configuration in the /config folder of Consul.

You can alter the path searched for by setting consul.client.config.path

Within the /config folder Micronaut will search values within the following folders in order of precedence:

Table 1. Configuration Resolution Precedence
FolderDescription

/config/application

Configuration shared by all applications

/config/application,prod

Configuration shared by all applications for the prod Environment

/config/[APPLICATION_NAME]

Application specific configuration, example /config/hello-world

/config/[APPLICATION_NAME],prod

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 folder /config/application.

Using curl to Write a Value

  1. 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.