Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 975
Theodosis Avatar asked Apr 22 '19 14:04

Theodosis


People also ask

Does environment variable override application properties?

Now, when your Spring Boot application starts, it will be given those environment variables, which will override your application. properties .

Can we use environment variables in properties file?

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.

Which Quarkus feature can you use to define configurations for different environments?

Quarkus uses MicroProfile Config annotations to inject the configuration properties in the application. You can use @Inject @ConfigProperty or just @ConfigProperty .

How do I set environment properties in spring boot?

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.


2 Answers

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.

like image 125
geoand Avatar answered Oct 20 '22 05:10

geoand


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

like image 20
S. Kadakov Avatar answered Oct 20 '22 05:10

S. Kadakov