【发布时间】:2018-04-03 09:21:50
【问题描述】:
我正在尝试使用h2 数据库在我的Spring boot 应用程序中对我的RestController 运行测试。
这是一些代码:
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT)
@ActiveProfiles("test")
public class E2E_EconomicOperatorAPIControllerTest {
@Autowired
private TestRestTemplate restTemplate;
@Test public void test_newEconomicOperator() {
//staff
}
}
但是当我运行它时,我得到了这个错误:
2018-04-03 12:16:57.084 WARN 14332 --- [ Thread-7] 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) [90121-196]
这是我的属性文件:
spring.datasource.url=jdbc:h2:mem:testdb;MODE=Oracle;DB_CLOSE_DELAY=-1
logging.level.org.gso.admin=DEBUG
logging.level.gso.gd.client=INFO
logging.level.org.springframework.web.client=WARN
logging.level.org.springframework=WARN
logging.level.org.thymeleaf=WARN
logging.level.root=WARN
【问题讨论】:
-
尝试更新您的数据源 URL,例如:jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE 它出现时没有退出关闭 h2 的数据库自动关闭的子句
-
是的,我在另一个 stackoverflow 问题中看到了这个答案,但徒劳无功。已经添加到我的属性文件中
-
这能解决问题吗?
标签: spring spring-boot junit4 h2