Search code examples
javaspringspring-bootflywayspring-ioc

How to make sure Flyway loads before my bean?


I have a Spring Boot application in which a Bean loads configuration-data from the database.

Right now I set up this Bean in the Configuration class. But it seems it loads before Flyway.

How to make sure Flyway has finished it's job before my beans get loaded?


Solution

  • You can initialize it before you start Spring Boot application:

    @SpringBootApplication
    public class Application {
    
        public static void main(String[] args) {
            // Init Flyway here
            SpringApplication.run(Application.class, args);
        }
    }
    

    Second option is to use @DependsOn annotation for your beans depending on Flyway.