如何在 Junit 测试期间访问内存数据库中的 H2

问题描述

在 JUnit 测试期间无法访问 H2 数据库控制台。由于数据库仅在测试运行时才会启动并运行,因此我尝试使用断点或睡眠命令来保持测试执行以在浏览器中访问 http://localhost:8080/h2-console,但得到“无法访问此站点错误

我正在使用的睡眠命令: TimeUnit.MINUTES.sleep(2);

POM.xml

spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1;Mode=Postgresql
spring.datasource.username=sa
spring.datasource.password=sa
hibernate.hbm2ddl.auto=create
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console
spring.jpa.hibernate.ddl-auto=none
spring.jpa.properties.hibernate.default_schema=
logging.level.root=DEBUG
hibernate.show_sql=true
logging.level.org.hibernate.sql=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.hibernate.use-new-id-generator-mappings=true
hibernate.dialect=org.hibernate.dialect.H2Dialect

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)