Spring的嵌入式H2数据源和DB_CLOSE_ON_EXIT。

15 浏览
0 Comments

Spring的嵌入式H2数据源和DB_CLOSE_ON_EXIT。

对于单元测试(如果你愿意,可以称之为集成测试),我在我的Spring配置中配置了一个嵌入式数据库,如下所示:


    

现在,当从命令行运行测试时,它们能够正常工作,但是在最后会出现一些错误(无害但令人烦恼):

WARN  2013-03-25 12:20:22,656 [Thread-9] o.s.j.d.e.H2EmbeddedDatabaseConfigurer 'Could not shutdown embedded database'
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-170]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:329) ~[h2-1.3.170.jar:1.3.170]
    ...
    at org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactoryBean.destroy(EmbeddedDatabaseFactoryBean.java:65) [spring-jdbc-3.2.1.RELEASE.jar:3.2.1.RELEASE]
    at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:238) [spring-beans-3.2.1.RELEASE.jar:3.2.1.RELEASE]

现在,异常中的提示通常是正确的,但是我该如何将此属性添加到嵌入式数据源中?我必须扩展它,手动配置以添加这样的“高级”功能吗?

0