gpt4 book ai didi

java - 尽管有 'DB_CLOSE_ON_EXIT=FALSE',但 H2 内存中测试数据库已关闭

转载 作者:搜寻专家 更新时间:2023-11-01 01:59:47 25 4
gpt4 key购买 nike

<分区>

我有一些简短的单元测试失败了,但出现以下异常:

javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not prepare statement
::
Caused by: org.hibernate.exception.GenericJDBCException: could not prepare statement
::
Caused by: org.h2.jdbc.JdbcSQLException: Database is already closed (to disable automatic closing at VM shutdown, add ";DB_CLOSE_ON_EXIT=FALSE" to the db URL) [90121-197]

来源是我的Spring Data AuditProvider,具体是这一行:

user = entityManager.createNamedQuery("findUserByUsernameAndTenant", User.class)
.setParameter("tenant", TenantService.DEFAULT_TENANT_ID)
.setParameter("username", UserService.USER_SYSTEM).getSingleResult();

错误在执行整个测试套件时发生,而不是仅在运行此测试类时发生。

这里是我正在使用的 TestRunner 等:

@RunWith(SpringRunner.class)
@SpringBootTest
@Transactional
@Rollback
public class MyTest {

这是我的数据源 URL:

spring.datasource.url: 'jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE'

所以“DB_CLOSE_ON_EXIT”似乎没有解决问题,知道这里发生了什么吗?

更新:

我刚刚意识到,只有在 Eclipse 中运行测试时才会发生这种情况,但它们在命令行中运行。虽然我偶尔会得到:

o.s.b.f.support.DisposableBeanAdapter    : Invocation of destroy method failed on bean with name 'inMemoryDatabaseShutdownExecutor': org.h2.jdbc.JdbcSQLException: Database is already closed (to disable automatic closing at VM shutdown, add ";DB_CLOSE_ON_EXIT=FALSE" to the db URL)

但我没有得到 PersistenceException 和堆栈跟踪信息。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com