I had the same problem.
I wanted my schema to be created by hibernate because of its independence from the database. I already faced the problem of coming up with a good scheme for my application in my jpa classes, I do not like to repeat myself.
But I want some data initialization to be done in a versioned way that is good for flying.
Spring loading starts the migration of the flyway to hibernation. To change it, I overloaded the boot spring initializer to do nothing. Then I created a second initializer that starts after hibernation ends. All you have to do is add this configuration class:
import org.flywaydb.core.Flyway; import org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.DependsOn; @Configuration public class MigrationConfiguration { @Bean FlywayMigrationInitializer flywayInitializer(Flyway flyway) { return new FlywayMigrationInitializer(flyway, (f) ->{} ); } @Bean @DependsOn("entityManagerFactory") FlywayMigrationInitializer delayedFlywayInitializer(Flyway flyway) { return new FlywayMigrationInitializer(flyway, null); } }
This code requires Java 8, if you have Java 7 or earlier, replace (f)->{} with an inner class that implements FlywayMigrationStrategy
Of course, you can do this in XML just as easily.
Be sure to add this to your application.properties:
flyway.baselineOnMigrate = true
source share