简体   繁体   English

使用H2数据库和Flyway进行Spring Boot应用测试失败

[英]Spring Boot Application Tests with H2 Database and Flyway Fails to Seed

I have an application I am trying to test using H2. 我有一个应用程序正在尝试使用H2进行测试。

Here's my application.yml: 这是我的application.yml:

spring:
  datasource:
    url: jdbc:h2:mem:appdb;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false
  jpa:
    database-platform: org.hibernate.dialect.H2Dialect
  flyway:
    url: jdbc:h2:mem:appdb;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false
    user: "root"
    password: ""
    locations: classpath:/db/migration, classpath:/db/seed

Flyway successfully runs the migrations (or at least it appears to), and the tables are created successfully as evidenced by the startup: Flyway成功运行了迁移(或至少看起来如此),并且启动成功证明了表已成功创建:

2018-04-03 08:47:42.956  INFO 17980 --- [           main] o.f.core.internal.command.DbMigrate      : Migrating schema "PUBLIC" to version 0
...

It even seems my seeds are "working": 甚至我的种子似乎在“起作用”:

2018-04-03 08:47:43.162  INFO 17980 --- [           main] o.f.core.internal.command.DbMigrate      : Migrating schema "PUBLIC" with repeatable migration Seed sample

It tells me it worked: 它告诉我它有效:

2018-04-03 08:47:43.188  INFO 17980 --- [           main] o.f.core.internal.command.DbMigrate      : Successfully applied 18 migrations to schema "PUBLIC" (execution time 00:00.283s)

My SQL files are written in PostgreSQL's SQL dialect. 我的SQL文件是用PostgreSQL的SQL方言编写的。 However, I've read that leaving hibernate on H2Dialect is fine. 但是,我读到H2Dialect上保持休眠状态很好。

When the tests go to run, it appears by the time the tests finish running there's nothing in the database, so the tests fail. 当测试开始运行时,它会在测试完成运行时显示,数据库中没有任何内容,因此测试失败。

My thoughts are that H2 is closing out the DB before the tests finish, but that seems strange to me. 我的想法是H2在测试完成之前就关闭了数据库,但这对我来说似乎很奇怪。 The seeds and the tables are working correctly. 种子和表格正常工作。

Is there anything I can do to verify everything is working here, or options I have not yet tried? 我有什么办法可以验证这里一切正常,或者我还没有尝试过的选项?

Try setting the Flyway schemas to your database name: 尝试将Flyway模式设置为您的数据库名称:

flyway:
  schemas: appdb

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Spring-Boot 进行 flyway 迁移后,Hibernate 无法验证内存中的 h2 数据库 - Hibernate fails to validate in-memory h2 database after flyway migration using Spring-Boot 使用 r2dbc 和 flyway 在 Spring Boot 应用程序中设置 h2 - Setup h2 in spring boot application with r2dbc and flyway 带有H2文件数据库的Spring Boot应用程序 - Spring Boot application with H2 file database Spring boot + Embedded Kafka + h2 数据库 + 单元测试 - Spring boot + Embedded Kafka + h2 database + unit Tests 在 Spring Boot 应用程序上使用 flyway 时如何在 H2 中加载初始数据? - How to load initial data in H2 when using flyway on spring boot application? 如何在 Spring Boot 应用程序中和使用 flyway 启动 H2 db TCP 服务器 - How to start H2 db TCP server within Spring Boot application and with flyway 与Spring Boot集成的Flyway不会在嵌入式H2数据库上执行迁移脚本 - Flyway integration with spring boot doesn't execute migration scripts on embedded H2 database 在哪里部署带有 H2 数据库的 Spring 引导应用程序 - Where to deploy Spring boot application with H2 database 使用 H2 数据库的带有 MVC 应用程序的 Spring Boot - Spring Boot with MVC application using H2 database 使用H2和Spring Boot进行测试 - Tests using h2 and spring boot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM