我有以下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]
答案 0 :(得分:0)
此异常是由属性文件中的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'
试试这个解决方案并告诉我它是否有用。