【发布时间】:2015-11-07 20:07:17
【问题描述】:
我实际上正在使用 Spring Boot 编写一个小型 Web 应用程序,并希望将(嵌入式)H2 数据库与 Spring Data JPA 和 Flyway 一起用于数据库迁移。
这是我的 application.properties:
spring.datasource.url=jdbc:h2:~/database;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;
spring.datasource.username=admin
spring.datasource.password=admin
spring.datasource.driver-class-name=org.h2.Driver
在我的 @SpringBootApplication 类的 main() 方法中,我执行以下操作:
ResourceBundle applicationProperties = ResourceBundle.getBundle("application");
Flyway flyway = new Flyway();
flyway.setDataSource(applicationProperties.getString("spring.datasource.url"), applicationProperties.getString("spring.datasource.username"), applicationProperties.getString("spring.datasource.password"));
flyway.migrate();
我添加了一个脚本,该脚本在数据库中创建了一个表 USER,Flyway 说它已正确迁移,但如果我连接到数据库,在模式 PUBLIC 中只列出了 Flyway 的 schema_versions 表。
如果我要添加另一个脚本,将基础数据插入到 USER 表中,迁移将失败,因为在我的 spring boot 应用程序重新启动后该表不存在。
谁能告诉我我的配置是否缺少?或者如果我的设置中有任何错误的假设......
【问题讨论】:
标签: spring-data-jpa h2 flyway