即使DB_CLOSE_DELAY = -1,H2连​​接也会关闭

时间:2018-03-09 02:23:33

标签: hibernate spring-boot spring-data-jpa h2 liquibase

我的application.properties上有这个H2网址:

spring.datasource.url=jdbc:h2:mem:myschema;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS myschema;MV_STORE=FALSE;MVCC=FALSE
spring.datasource.driver-class-name=org.h2.Driver
spring.h2.console.enabled=true
spring.h2.console.path=/db
spring.h2.console.settings.trace=true
spring.h2.console.settings.web-allow-others=true
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect

但是当我的应用程序启动时,我有这些日志。

2018-03-09 02:48:12.745 DEBUG 7248 --- [  restartedMain] o.s.j.d.DriverManagerDataSource          : Creating new JDBC DriverManager Connection to [jdbc:h2:mem:myschema;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS myschema;MV_STORE=FALSE;MVCC=FALSE]
2018-03-09 02:48:12.828  WARN 7248 --- [  restartedMain] o.h.e.j.e.i.JdbcEnvironmentInitiator     : HHH000342: Could not obtain connection to query metadata : Schema "myschema" not found [90079-196]
2018-03-09 02:48:12.835  INFO 7248 --- [  restartedMain] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2018-03-09 02:48:12.855  INFO 7248 --- [  restartedMain] o.h.e.j.e.i.LobCreatorBuilderImpl        : HHH000422: Disabling contextual LOB creation as connection was null
2018

似乎H2在连接后才关闭,正如您在URL上看到的那样,它不应该。 我使用Liquibase在该模式上创建我的表,并且当数据库关闭时,它引发了这个异常:

Caused by: liquibase.exception.DatabaseException: org.h2.jdbc.JdbcSQLException: Schema "myschema" not found [90079-196]
    at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:390) ~[liquibase-core-3.5.5.jar:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1769) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1706) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    ... 21 common frames omitted
Caused by: org.h2.jdbc.JdbcSQLException: Schema "myschema" not found [90079-196]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:345) ~[h2-1.4.196.jar:1.4.196]
    at org.h2.message.DbException.get(DbException.java:179) ~[h2-1.4.196.jar:1.4.196]
    at org.h2.message.DbException.get(DbException.java:155) ~[h2-1.4.196.jar:1.4.196]
    at org.h2.engine.Database.getSchema(Database.java:1755) ~[h2-1.4.196.jar:1.4.196]
    at org.h2.engine.Session.setCurrentSchemaName(Session.java:1265) ~[h2-1.4.196.jar:1.4.196]
    at org.h2.jdbc.JdbcConnection.setSchema(JdbcConnection.java:1928) ~[h2-1.4.196.jar:1.4.196]
    at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:210) ~[spring-jdbc-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:169) ~[spring-jdbc-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:385) ~[liquibase-core-3.5.5.jar:na]
    ... 23 common frames omitted

我正在使用Spring Boot 2来管理Hibernate(5.2.14.Final)和H2(1.4.196)。

感谢您的帮助

0 个答案:

没有答案