Reuse spring boot properties for liquibase configuration

Viewed 38

I want to start use liquibase in my Spring Boot app. Now I already have db configuration, something like:

abc.datasource.jdbc-url=
abc.datasource.username=
abc.datasource.password=

For liquibase usage I also added the parameters to the same file with a same values:

spring.liquibase.url=
spring.liquibase.user=
spring.liquibase.password=

The question is: is it possible to configure it somehow to avoid duplication of the configuration values?

3 Answers

You can access defined properties in application.yaml:

spring:
  application:
    name: application-name
some-value: ${spring.application.name} # will be equal to 'application-name'

The order of the properties is not important.

If you want to do it the same file declare shared properties and reference them below

shared.datasource.jdbc-url=
shared.datasource.username=
shared.datasource.password=

abc.datasource.jdbc-url=${shared.datasource.jdbc-url}
abc.datasource.username=${shared.datasource.username}
abc.datasource.password=${shared.datasource.password}

spring.liquibase.url=${shared.datasource.jdbc-url}
spring.liquibase.user=${shared.datasource.username}
spring.liquibase.password=${shared.datasource.password}
Related