10

I would like to override the properties I have configured in my configuration file in my Quarkus application.

How can I accomplish that?

bruno
  • 2,213
  • 1
  • 19
  • 31
geoand
  • 60,071
  • 24
  • 172
  • 190
  • What about `System.setProperty()`? Here's an example that solved my problem: https://stackoverflow.com/a/61449847/3806701 – cs_pupil Oct 20 '20 at 15:35
  • That will most likely not work in Quarkus (depending on when you do it) – geoand Oct 20 '20 at 19:49

2 Answers2

12

Properties in Quarkus are generally configured in src/main/resources/application.properties.

This is true both for properties that configure the behavior of Quarkus (like the http port it listens to or the database URL to connect to for example) and properties that are specific to your application (for example a greeting.message property).

The overridability of the former depends on the configuration in question. For example, the http properties (like quarkus.http.port) are overridable.

The later are always overridable at runtime.

When running a Quarkus application in JVM mode you can, for example, do:

java -Dgreeting.message=hi -jar example-runner.java

Similarly, when running a Quarkus application that has been converted to a native binary using the GraalVM (specifically the SubstrateVM system), you could do:

./example-runner -Dgreeting.message=hi

More information can be found on the "Quarkus - Configuring Your Application" official guide

bruno
  • 2,213
  • 1
  • 19
  • 31
geoand
  • 60,071
  • 24
  • 172
  • 190
  • What if you have loads of properties that you need to configure for different environments? Seems inefficient to list them all on the command line. Is it not possible to apply an override file location at runtime? – Sean Mar 27 '19 at 11:30
  • 2
    Currently you can't do that, but there is an issue for it: https://github.com/quarkusio/quarkus/issues/1218 – geoand Mar 27 '19 at 11:44
  • 3
    There is an option for the time being: If you place an `application.properties` file inside the a `config` directory (which is itself in the current working directory) then that will take precedence over what is in the project. – geoand Mar 27 '19 at 14:03
  • @geoand that is very interesting. I cannot find a reference in the doc for this, however, can you provide more information? I am looking for a way to make this work with configmaps. Would your method work if I had a config folder next to the final .jar application? – csotiriou May 22 '19 at 20:02
  • 2
    @csotiriou there was some issue about documenting it which I can't find now... However the code is the ultimate source of truth :P. https://github.com/quarkusio/quarkus/blob/master/core/runtime/src/main/java/io/quarkus/runtime/configuration/ApplicationPropertiesConfigSource.java#L70 – geoand May 23 '19 at 06:35
  • 2
    here is the documentation link [https://quarkus.io/guides/config#overriding-properties-at-runtime](https://quarkus.io/guides/config#overriding-properties-at-runtime) – Tushar Feb 05 '20 at 15:18
  • the previous link doesn't work, here is [valid one](https://quarkus.io/guides/config-reference#application-properties-file) – Olivier Boissé Oct 15 '22 at 18:13
0

Other way to override properties is using Quarkus Profiles. This way you can create separated application files for each environment (if intended). For specific environment config file, include the profile name before all properties

Base application file:

quarkus:
    http:
        port: 9090

Environment specific config file:

"%dev":
    quarkus:
        http:
            port: 8181

enter image description here

daegyu
  • 96
  • 1
  • 2