1
votes

In my Spring Boot app I use Flyway for DB migrations and MyBatis together. Problem is that MyBatis is initialized before Flyway, so some DB operations are called (within @PostConstruct) before DB migration.

If I take a look into FlywayAutoConfiguration there is:

@AutoConfigureAfter({DataSourceAutoConfiguration.class, ...})
public class FlywayAutoConfiguration { 
  ...

As I understand, I need override FlywayAutoConfiguration and add:

@AutoConfigureAfter({DataSourceAutoConfiguration.class})
@AutoConfigureBefore({MybatisAutoConfiguration.class})
public class FlywayAutoConfiguration { 
  ...

Not sure how to do that. Thanks for any help.

1
Have you solved your problem? I am having the same problem. - Lisek

1 Answers

0
votes

I would declare a @Bean definition for flyway() and then another @Bean definition for whatever data source in your possession, making sure to initialize it after the flyway bean , which you can simply do by adding @DependsOn("flyway") annotation on your data source bean declaration.

This way you make sure whatever data init tasks launched by your data source will come after flyway has done its job.