【发布时间】:2015-05-29 05:29:12
【问题描述】:
我尝试在 Spring Boot 项目中使用 Hibernate 和 Spring JPA 集成 Flyway 以进行迁移。我收到以下异常:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flyway' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.api.FlywayException: Found non-empty schema "PUBLIC" without metadata table! Use init() or set initOnMigrate to true to initialize the metadata table.
我的pom.xml 是这样的:
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>3.2</version>
</dependency>
我正在使用 Hibernate 和一个用于 postgres(开发阶段)和 h2(本地)的配置 java 文件。签名看起来像这样:
@Bean(initMethod = "migrate")
public Flyway flyway() {
Flyway fly = new Flyway();
fly.clean();
fly.init();
//flyway.setInitOnMigrate(true);
fly.setSchemas("SBA_DIALOG");
//flyway.setLocations("filesystem:src/main/resources/db/migration");
fly.setDataSource(this.dataSource());
fly.migrate();
return fly;
}
@Bean(name = "sbaEntityManagerFactory") @DependsOn("flyway")
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
...
我找不到有关此问题中描述的问题的任何信息。 有人可以帮忙吗?
【问题讨论】:
-
Spring Boot 已经支持 flyway 唯一需要的就是添加 flyway 作为依赖项......我建议阅读 manual 和 configuration properties。对我来说,您似乎正在使用 boot 并非常努力地解决它(例如显式配置所有内容)。
-
很奇怪:如果你自己配置flyway,spring boot不应该启动flyway自动配置(问题是是否有必要)。但是错误来自启动自动配置。但是尝试将
flyway.initOnMigrate= true添加到您的 application.properties 并删除您自己的飞行路初始化:) -
@sodik 实际上我已经在类路径(3.2.1)中飞行,但它不起作用。可能是什么问题?
-
对我来说,问题是flyway和spring版本不匹配
标签: java spring hibernate spring-boot flyway