I have integrated Liquibase with my spring Boot application. The one confusion which I have is that - does Liquibase run before registering all the beans. If we want to fetch some property from the DB in the bean declaration method and that property is written by the sql script which will be executed by Liquibase. So, which of the two things will happen first?
I do know that liquibase automatically gets integrated to the startup of the spring boot application i.e, it runs everytime, the application runs. But, does it get loaded before loading other beans of the same application?
My liquibase dependency :
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>3.8.2</version>
</dependency>
The Liquibase Spring Boot integration ensures the application database is updated along with the application code by using Spring Boot auto-configuration and features. To use Liquibase and Spring Boot: Install Maven and add it to your path. Ensure you have Java Development Kit (JDK 8, 11, or 16).
In Spring Boot, you can use appContext. getBeanDefinitionNames() to get all the beans loaded by the Spring container.
liquibase. enabled=false application property disables Liquibase.
So, which of the two things will happen first?
So you should be able to get data (which Liquibase has just inserted) from database during bean initialization.
But as was suggested in the comments, you should try it yourself and add logs to your bean initialization methods. This will give you a way better understanding of Spring-Boot applications start-up process.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With