Spring Boot With Liquibase(On Demand Run)

Recently while working on project, we came to a requirement where we need to create new database on mysql and then migrate data from script file.

Three options came to my picture – 1. Execute Sql Scripts using Spring JDBC template

2. Use Flyway to do migration

3.Use Liquibase to do migration

So We thought to get a try on Spring boot and Liquibase which will help us in data migration. Spring boot support liquibase  by default if we provide liquibase properties in application.property file. Once you added property and changeLog files, Spring boot while application is coming up, it will run migration from Changelog file and apply it on database. But we were in situation where we want to do migration on demand not on when spring boot application is coming up.

Steps to create Spring Boot application with Liquibase (Assumpation you are using STS)

  1. Create New Spring Starter project
  2. Select JPA,Web,Mysql dependency and create Spring boot application
  3. Add liquibase dependency into gradle.build file
  4. Add database related properties into application property file
  5. exclude liquibaseautoconfiguration from spring auto configuration annotation
  6. Add changeLog file at resource->db->changelog>db.changelog-master.yaml
  7. add code to run liquibase migration on demand.

Project Structure should be as show below :-


project structure


Project sample code is availabe on github repo- GITHUB

Hope this is helpful for who is looking to do on demand data migration using liquibase and Spring boot.

Cheers 🙂



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s