【问题标题】:H2 DB Url errorH2 DB 网址错误
【发布时间】: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]

【问题讨论】:

    标签: java spring-boot h2 embedded-database


    【解决方案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'
    

    试试这个解决方案,告诉我它是否有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-10
      • 2018-04-01
      • 2020-05-15
      • 2019-09-28
      • 1970-01-01
      • 2017-01-16
      • 2021-12-04
      • 1970-01-01
      相关资源
      最近更新 更多