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?
Asked
Active
Viewed 2.6k times
21

Theodosis
- 792
- 2
- 7
- 22
2 Answers
52
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.

geoand
- 60,071
- 24
- 172
- 190
-
It does work with the latest versions of Quarkus (I've tested for versions >= 1.1) – geoand Feb 21 '20 at 19:18
-
What about int default values can we just use -1 as in this example? ``` quarkus.mailer.from=${SYSTEM_EMAIL:-} quarkus.mailer.port=${EMAIL_SERVER_PORT:-1} ``` To specify empty string using `-` and default-int is `-1` – Hhovhann Feb 05 '21 at 13:24
-
I am not sure I understand your problem. Can you try and explain it a little more? – geoand Feb 07 '21 at 05:39
-
I mean I am using for defaut values `-` for empty string and `-1` for int initial values. Is this correct usages ? Cannot find any best practises about this in Quarkus docs. – Hhovhann Feb 08 '21 at 06:48
-
You can alternatively make the Java field `Optional` and not have to pass a default value – geoand Feb 08 '21 at 07:28
-
Yes, but in my case I am using those values vor mailing integration and not injecting them as a fields. Probably will upgrade platform to 1.11.1.final soon, where we have warnings instead of server keystore error when using ${HOST} without default values – Hhovhann Feb 09 '21 at 08:23
-
Where is this documented ?not at https://quarkus.io/guides/config – puio Jun 06 '23 at 08:28
-
1https://quarkus.io/guides/config-reference#property-expressions – geoand Jun 06 '23 at 11:28
10
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

S. Kadakov
- 861
- 1
- 6
- 15