Brian Hesselmann
Brian Hesselmann

Reputation: 1

Using environment variables with @ConfigMapping

I'm using Quarkus 2.16 with an application.properties file. The problem I have is with @ConfigMapping and map. Looking at the docs here at 1.5.3: https://quarkus.io/version/2.16/guides/config-mappings#nested-groups

It describes how to use a map inside your application.properties. I can't figure out how to change this map with environment variables. Is this possible?

Often I want to set my properties using environment variables like this:

application.folder=${FOLDER:folder}

Here I can use the FOLDER environment variable to change the application properties.

If possible this would allow me to deploy my application with just config changes, without needing to change the application.properties file itself.

Upvotes: 0

Views: 355

Answers (1)

Roberto Cortez
Roberto Cortez

Reputation: 1163

Yes, it is possible, but remember that environment variables cannot represent the full spectrum of regular property names. For all the conversion rules, please check: https://quarkus.io/guides/config-reference#environment-variables

You don't need to add an extra layer of indirection with expressions in your example. Because environment variables have a higher ordinal than application.properties, you can set any value and override it with APPLICATION_FOLDER.

Quarkus also supports external properties files, either in a working directory config or adding arbitrary files with the configuration `quarkus.config.locations. Please check:

https://quarkus.io/guides/config-reference#application-properties-file

https://quarkus.io/guides/config-reference#quarkus-config-config_quarkus.config.locations

Upvotes: 0

Related Questions