I want to import some data on the SQL server database, I'm using Spring Boot 2.3.4. I use also Hibernate to generate the tables.
I added flyway core in pom:
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
Created the configuration file:
import org.flywaydb.core.Flyway;
import org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer;
import org.springframework.boot.autoconfigure.flyway.FlywayMigrationStrategy;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
@Configuration
public class FlyWayConfiguration {
@Bean
FlywayMigrationInitializer flywayInitializer(Flyway flyway) {
return new FlywayMigrationInitializer(flyway, (f) ->{} );
}
@Bean
@DependsOn("entityManagerFactory")
FlywayMigrationInitializer delayedFlywayInitializer(Flyway flyway) {
return new FlywayMigrationInitializer(flyway, new FlywayMigrationStrategy() {
@Override
public void migrate(Flyway flyway) {
flyway.migrate();
}
});
}
}
I created a file on resources/db/migration/V1_0_1__InitialData.sql
Now I'm having this error
Error creating bean with name 'delayedFlywayInitializer' defined in class path resource
[com/ikun/mkj/config/MigrationConfiguration.class]: Circular depends-on relationship between
'delayedFlywayInitializer' and 'entityManagerFactory' at
org.springframework.beans.factory.support.AbstractBeanFactory
I don't know how to fix this, I searched for solution but couldn't make. Can someone help me please?