Liquibase with Spring Boot

Data centre
Reading Time: 3 minutes

The purpose of this blog is to show you the process of using Liquibase as a piece of your Spring Boot workflow. Springboot makes it easy to create standalone, production-maven Spring-based applications.


Liquibase is an open-source database that has an independent library for tracking, managing, and applying database schema changes. Liquibase was started in 2006 and it is used to allow easier tracking of database changes, especially in an agile software development environment.


Make sure that you have  Java Development Kit (JDK 8, 11, or 16).

Use of Liquibase with Spring Boot as a Maven Project

Use Liquibase with spring-boot to create and configure single spring applications and automate your database updates. Spring-boot with build systems like Maven permits you to create Java applications initiated by running java -jar or war deployments.

The Liquibase Spring Boot integration makes the application database updated together with the application code by applying Spring Boot auto-configuration and features.

To use Liquibase and Spring Boot:

  1. Firstly, install a maven project and add it to your system.
  2. Make sure you have Java Development Kit (JDK 8, 11, or 16).
  3. Generate a basic maven project by using your IDE :
  • If you already have an existing spring-boot project, then add the liquibase-core dependency on your project pom.xml.
  • To dynamically create a new spring-boot project, follow the Spring Boot Getting Started documentation.
  • To create a basic spring-boot project, you can also use a web-based service that is called Spring Initializr.

Insert the below information in Spring Initializr.

  • Project Type: Maven
  • Language Used: Java
  • Spring-Boot: the version you need
  • Project Description :
    • Group: com. knoldus.liquibase
    • Artifact: spring-boot-liquibase-example project
    • Name: spring-boot-project
    • Description: Liquibase-spring-boot project example
    • Package name: com.knoldus.spring-boot.liquibase-example project
    • Packaging Type: Jar
    • Java version: 8, 11, or 16
  • Dependencies: Spring Data JPA and Liquibase Migration. This service will add our database driver dependency and any developer tool.
  • Now click on  GENERATE to download your created project template as a .zip file.

After selecting the above options, the project window needs to look similar to the below screenshot:

Finally, Click GENERATE to upload your project template as a zip file. After you require to extract it and open it in your IDE.

Run the Liquibase database with Spring Boot and the Maven project

  1. Open the existing Spring Boot file. To get the file, traverse to src/main/resources/
  2. Add the following properties to run Liquibase migrations. Now update the values depending on your database prerequisite:


spring.datasource.username = ${dbName}

spring.datasource.password = ${dbPass}

  1. Create a new text file known as pom.xml or utilize the pom.xml file created for your project using the Spring Initializr.
  2. Specify attributes in your pom.xml based on the example:
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns=""







		<relativePath/> <!-- lookup parent from repository -->






	<description>Demo project for Spring Boot</description>
















































Setting your changelog file :

  • Create a changelog file: src/main/resources/db/changelog/db.changelog-master.xml. Liquibase is also keep up the .sql, .yaml, or .json changelog formats. To get more information, see Introduction to Liquibase and Getting Started with Liquibase.
  • Add the following code snippet to your changelog file, including changesets:
<?xml version="1.0" encoding="UTF-8"?>





  <changeSet id="01" author="Sankata">

    <createTable tableName="books"

      remarks="A table to contain all books">

      <column name="id" type="int" autoIncrement="true">

        <constraints nullable="false" unique="true" primaryKey="true"/>


      <column name="name" type="varchar(255)">

        <constraints nullable="false" unique="true"/>


      <column name="author" type="int">

        <constraints nullable="false"/>



    <createTable tableName="authors"

      remarks="A table to contain all the authors">

      <column name="id" type="int" autoIncrement="true">

        <constraints nullable="false" primaryKey="true"/>


      <column name="name" type="varchar(100)">

        <constraints nullable="false"/>



    <addForeignKeyConstraint baseTableName="books" baseColumnNames="author"


      referencedTableName="authors" referencedColumnNames="id"/>



To run the first migration with the below command

mvn compile package

Written by 

He is a Software Consultant at Knoldus Inc. He has done B.Tech from Dr. APJ Kalam Technical University Uttar-Pradesh. He is passionate about his work and having the knowledge of various programming languages like Java, C++, Python. But he is passionate about Java development and curious to learn Java Technologies. He is always impatient and enthusiastic to learn new things. He is good skills of Critical thinking and problem solving and always enjoy to help others. He likes to play outdoor games like Football, Volleyball, Hockey and Kabaddi. Apart from the technology he likes to read scriptures originating in ancient India like Veda,Upanishad,Geeta etc.