'Quarkus: Overwrite DEV profile config with empty values for Postgres properties

I'm using Quarkus (2.7.3.Final) with Postgres (quarkus-jdbc-postgresql).

And I really like Quarkus' approach that if you configure no username, password and url for your datasource it will try to start a testcontainer and emulate the database, when you start the app in development mode.

So for example if you define this in your application.yml (or application.properties), Quarkus will start a Postgres testcontainer for you, when you start the app with ./mvnw clean quarkus:dev:

quarkus:
  datasource:
    username:
    password:
    db-kind: postgresql
    jdbc:
      driver: org.postgresql.Driver
      url:

The log says "Dev Services for the default datasource (postgresql) started." Pretty neat! :-)

However, what I really want is to define my real/productive database connection settings in my application.yml. And then overwrite them in the application-dev.yml, so that only in the development mode the testcontainer is started:

  • application.yml with PROD settings:
    quarkus:
      datasource:
        username: myuser
        password: mypassword
        db-kind: postgresql
        jdbc:
          driver: org.postgresql.Driver
          url: jdbc:postgresql://hostname:5432/mydb
  • application-dev.yml with DEV settings:
    quarkus:
      datasource:
        username:
        password:
        jdbc:
          url:

But overwriting the properties with null values doesn't work, when I start the app in development mode I get the error:

Datasource '<default>': Connection to hostname:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.

The overwriting itself works, if I change my application-dev.yml to use an embedded H2 instead of the implicit testcontainer, the application starts:

  • application-dev.yml with H2 settings:
    quarkus:
      datasource:
        username: sa
        password: mypassword
        db-kind: h2
        jdbc:
          driver: org.h2.Driver
          url: jdbc:h2:mem:mydb;DB_CLOSE_DELAY=-1

So my question is: How can I overwrite my datasource configuration with null values, so that Quarkus uses testcontainers in dev mode?

And by the way, switching from a application.yml to Quarkus default application.properties unfortunately did not help.

Thanks a lot!



Solution 1:[1]

Just to complete this: Combining the previous answers and comments using the prod profile this my solution:

  • application.yml with DEV settings:
    quarkus:
      datasource:
        username:
        password:
        db-kind: postgresql
        jdbc:
          driver: org.postgresql.Driver
          url:
  • application-prod.yml with PROD settings:
    quarkus:
      datasource:
        username: myuser
        password: mypassword
        jdbc:
          url: jdbc:postgresql://hostname:5432/mydb

The application-dev.yml isn't needed this way. Thanks folks! :-)

Solution 2:[2]

Following Quarkus' official documentation,

If a profile does not define a value for a specific attribute, the default (no profile) value is used

This behaviour will be useful in many cases, but in yours might lead to the inability to override properties once defined in the default profile back to their empty state.

I would suggest you to swap your profiles around i.e. treat the null-valued dev configuration as a default and provide meaningful non-null prod values in an overriding profile.

If you are worried that dev values might be used this way accidentally in prod environment, remember that Quarkus is going to use prod profile by default if not told otherwise.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Christian Schwörer
Solution 2 ryfterek