After I talked about how to add Liquibase to your project and how to update your database together with your application code, it’s time to integrate Liquibase into your application so that you can execute the update automatically. Special thanks to Carlos Feria who asked for this post in a comment.
The automatic execution of the update scripts is especially interesting when you build smaller applications that don’t run in a highly regulated enterprise environment. In these situations, it’s often not possible to run the update process yourself and there might be no operations team which executes the SQL scripts. So, you need to run the database update automatically when you start your application.
There are several ways to do that. If you’re building a plain Java application, you can use the Liquibase API to trigger the update. And it gets even easier, if you’re using a CDI container, e.g. in a Java EE application server, or Spring. I will show you all 3 approaches in this post.
Let’s start with the plain Java environment.