Spring Boot: Hibernate and Flyway boot order

前端 未结 6 667
一整个雨季
一整个雨季 2020-12-09 03:52

I have created Spring application. Pom xml is attached.

It has a config like this (below) and some db/migration/V1__init.sql for Flyway db migration tool.

It

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-09 04:23

    This works for me with Spring Boot 2.3.1

    1- you need to disable boot for Flyway, by insert into resources/application.properties:

    spring.flyway.enabled = false
    

    2- Start your migration scripts from version 2 as V1 is used as a baseline, V1 file will be ignored.

    3- Make the @SpringBootApplication class implements CommandLineRunner interface (It is used to execute the code after the Spring Boot application started ). and it will be like this:

    @SpringBootApplication
    public class SpringBootApplication implements CommandLineRunner {
    
        @Autowired
        DataSource dataSource;
    
        public static void main(String[] args) {
            SpringApplication.run(SpringBootApplication.class, args);
        }
    
        @Override
        public void run(String... args) throws Exception {
            Flyway.configure().baselineOnMigrate(true).dataSource(dataSource).load().migrate();
        }
    
    }
    

    This answer helped me

提交回复
热议问题