Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Liquibase runs before registering all the beans in spring boot application?

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>
like image 841
Pranjal Kumar Avatar asked Feb 18 '20 06:02

Pranjal Kumar


People also ask

How does Liquibase work with spring boot?

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).

How do you get all the beans in your spring boot application?

In Spring Boot, you can use appContext. getBeanDefinitionNames() to get all the beans loaded by the Spring container.

How do I disable Liquibase spring boot?

liquibase. enabled=false application property disables Liquibase.


1 Answers

So, which of the two things will happen first?

  1. Liquibase runs it's scripts.
  2. Spring-Boot initializes your beans.

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.

like image 166
htshame Avatar answered Oct 30 '22 20:10

htshame