Home > Net >  Reuse spring boot properties for liquibase configuration
Reuse spring boot properties for liquibase configuration

Time:09-10

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?

CodePudding user response:

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.

CodePudding user response:

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}

CodePudding user response:

I believe you do not need to repeat the same parameters, as those will be automatically picked up for Liquibase.

See example here: https://github.com/juliuskrah/spring-boot-liquibase/blob/main/src/main/resources/application.properties

  • Related