Search code examples
javapropertiesspring-bootliquibase

how can I access system properties using spring boot and Liquibase changeset yaml file


A Spring Boot Java application using Liquibase to manage the database schema changes is started with a parameter (e.g. dev, int) specifying the environment it runs in.

There are corresponding properties files (e.g. dev.properties, int.properties) which define properties for the corresponding environment.

So in dev.properties there is e.g.

url.info=http://dev.app.info

and in tst.properties there is

url.info=http://tst.app.info

The application reads in the properties from the file corresponding to the passed in parameter.

This mechanism works fine when the application is deployed and started in each environment. There are many instances when the corresponding property is used.

However, it doesn't work with a Liquibase yaml changeset containing the following insert statement

- insert:
        tableName: result
        columns:
          - column:
              name: id
              value: a88b6708-5c9f-40c4-a3ca-41e7a6b57fc8
          - column:
              name: infoUrl
              value: ${url.info}

I have tried double and single quotes in the yaml file, i.e. "${url.info}" and '${url.info}' but the database always ends up with the String ${url.info}

Is there another notation I have to use for properties in yaml files? or Can properties not be referenced in liquibase yaml files the way they can with xml files?


Solution

  • As you are using Spring Boot, you can use its application.properties file to define change log parameters.

    Any property with a name that begins with spring.liquibase.parameters. can be referenced in a changelog. For example, the property spring.liquibase.parameters.url.info can be referenced as ${url.info} in your changelog (YAML or XML).

    To use different configuration files for dev, QA, production etc you can use profiles and profile-specific configuration files. For example, the application-dev.properties file will only be loaded when the dev profile is active.