2

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?

luboskrnac
  • 23,973
  • 10
  • 81
  • 92
yglodt
  • 13,807
  • 14
  • 91
  • 127

1 Answers1

2

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.

luboskrnac
  • 23,973
  • 10
  • 81
  • 92
  • Probably I can also create e Flyway bean myself in the Config class, and have it @Ordered before my Beans ... ? – yglodt Jun 22 '16 at 08:35
  • I updated my answer. `@Ordered` seem to be used for different purpose. – luboskrnac Jun 22 '16 at 09:11
  • Strangely, Flyway did just not autoconfigure in my application. I have now created the bean manually, and used @DependsOn("flyway") for my Bean. – yglodt Jun 23 '16 at 19:50