H2 DB 网址错误
Posted
技术标签:
【中文标题】H2 DB 网址错误【英文标题】:H2 DB Url error 【发布时间】:2018-02-22 18:57:49 【问题描述】:我有以下 H2 数据源配置
jdbc.driverClassName=org.h2.Driver
jdbc.url=jdbc:h2:mem:test;INIT=CREATE SCHEMA IF NOT EXISTS TESTSCHEMA\;RUNSCRIPT FROM '~/schema-test.sql'\;RUNSCRIPT FROM '~/data-test.sql';DB_CLOSE_DELAY=-1
jdbc.user=xyzapp
jdbc.pass=x161jq3
当我运行它时,我收到以下错误
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in com.allegis.search.ConfigTest: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceInitializer': Invocation of init method failed; nested exception is org.springframework.jdbc.datasource.init.UncategorizedScriptException: Failed to execute database script; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; ne
sted exception is org.h2.jdbc.JdbcSQLException: URL format error; must be "jdbc:h2: .|mem:[name] | [file:]fileName | tcp|ssl:[//]server[:port][,server2[:port]]/name
[;key=value...]" but is "jdbc:h2:mem:test" [90046-196]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:189) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1193) ~[spring-beans-4.3.12.R
ELEASE.jar:4.3.12.RELEASE]
【问题讨论】:
【参考方案1】:此异常是由您的属性文件中不正确的jdbc.url
引起的。您需要转义反斜杠字符:
jdbc.url=jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS TESTSCHEMA\\;RUNSCRIPT FROM '~/schema-test.sql'\\;RUNSCRIPT FROM '~/data-test.sql'
试试这个解决方案,告诉我它是否有用。
【讨论】:
以上是关于H2 DB 网址错误的主要内容,如果未能解决你的问题,请参考以下文章
django中所有URL的编程错误,postgres在db中找不到表?