configure dataSource for liquibase in spring boot

前端 未结 2 1996
臣服心动
臣服心动 2020-12-19 02:23

I have a spring boot application and I want to add liquibase configuration change log for it.

I have created a LiquibaseConfig class for configuring liquibase:

相关标签:
2条回答
  • 2020-12-19 02:52

    I had a similar construct for my application, have you tried injecting a more generic javax.sql.DataSource instead?

    My guess is that Spring uses the non-specific type for this bean, on top of that you shouldn't even use a database-specific type if your application could be configured to use a totally different source, i.e. by just changing the datasource URL in the configuration file.

    0 讨论(0)
  • 2020-12-19 03:00

    Here's a simple step to integrate liquibase in spring boot

    STEP 1

    Add liquibase dependency

    Gradle

    runtime "org.liquibase:liquibase-core"
    

    Maven

    <dependency>
        <groupId>org.liquibase</groupId>
        <artifactId>liquibase-core</artifactId>
        <scope>runtime</scope>
    </dependency>
    

    STEP 2

    Add liquibase changelog file path in application.yml

    liquibase:
      enabled: true #this is optional as enabled by default
      change-log: classpath:/liquibase/db-changelog.xml
    

    Notice property liquibase.change-log. I'm referring path as /liquibase/db-changelog.xml. so you should have a file name db-changelog.xml inside src/main/resources/liquibase/

    STEP 3

    Add your changesets on the file and when Spring-Boot application is started (spring-boot:run) your changeset will be loaded.

    This will use default dataSource that your app uses.

    More Info: http://docs.spring.io/spring-boot/docs/1.4.3.RELEASE/reference/htmlsingle/#howto-execute-liquibase-database-migrations-on-startup

    Update

    For Spring Boot 2.0 as @veben pointed out in comment use

    spring:
        liquibase:
            change-log: #path
    
    0 讨论(0)
提交回复
热议问题