Theodosis
Theodosis

Reputation: 954

Quarkus how to set environment variables in application.properties

recently I swapped from thorntail to quarkus and I'm facing some difficulties trying to find how to set environment variables in application.properties in thorntail I used something like this ${env.HOST: localhost} that basically means put environment variable, if you don't find anything put localhost as default is that possible to quarkus application.properties? I haven't found any issue on GitHub or someone that have an answered this problem?

Upvotes: 25

Views: 39840

Answers (2)

geoand
geoand

Reputation: 64011

In application.properties you can use:

somename=${HOST:localhost}

which will correctly expand the HOST environment variable and use localhost as the default value if HOST is not set.

See this for more information.

Upvotes: 62

S. Kadakov
S. Kadakov

Reputation: 919

Alternatively, you do not need refere environment variable in application.properties, just refere variable in your code directly:

@ConfigProperty(name = "my.property", defaultValue = "default value")
String myProperty;

and specify it using env variable like this:

export MY_PROPERTY="env var" && java -jar myapp.jar

or using command line definition -D

java -Dmy.property="CL key" -jar myapp.jar

Please refere Quarkus configuration guide https://quarkus.io/guides/config

Upvotes: 12

Related Questions