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?
Now, when your Spring Boot application starts, it will be given those environment variables, which will override your application. properties .
You can put environment variables in your properties file, but Java will not automatically recognise them as environment variables and therefore will not resolve them. In order to do this you will have to parse the values and resolve any environment variables you find.
Quarkus uses MicroProfile Config annotations to inject the configuration properties in the application. You can use @Inject @ConfigProperty or just @ConfigProperty .
Environment-Specific Properties File. If we need to target different environments, there's a built-in mechanism for that in Boot. We can simply define an application-environment. properties file in the src/main/resources directory, and then set a Spring profile with the same environment name.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With