Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java H2:JdbcSQLException:URL格式错误_Java_Url_Jdbc_H2 - Fatal编程技术网

Java H2:JdbcSQLException:URL格式错误

Java H2:JdbcSQLException:URL格式错误,java,url,jdbc,h2,Java,Url,Jdbc,H2,我将一个连接到真实数据库的配置替换为另一个应该连接到内存中数据库的配置。我想使用此配置进行集成测试。一个简单的测试如下所示 import org.junit.Test; 导入org.junit.runner.RunWith; 导入org.springframework.boot.test.context.SpringBootTest; 导入org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.cla

我将一个连接到真实数据库的配置替换为另一个应该连接到内存中数据库的配置。我想使用此配置进行集成测试。一个简单的测试如下所示

import org.junit.Test;
导入org.junit.runner.RunWith;
导入org.springframework.boot.test.context.SpringBootTest;
导入org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@春靴测试
公共类WebApplicationTests{
@试验
public void contextLoads(){}
}
pom.xml中的新配置


集成测试
jdbc:h2:mem:db\u name\u测试;模式=MSSQLServer;DB_关闭_上的_退出=错误;DB_CLOSE_DELAY=-1;INIT=如果不存在,则创建架构db_name_test\\;设置架构db\u name\u测试
sa
com.h2数据库
氢
1.4.195
这些属性被注入到资源文件中,然后由Spring在上下文初始化期间获取。XML上下文中的数据源配置如下所示:


我使用此命令构建项目并执行测试:

mvn-T 1C清洁集成测试-P集成测试
使用先前配置的测试现在抛出以下异常

堆栈跟踪

2018-03-13 13:36:04.627错误9076---[main]o.s.test.context.TestContextManager:在允许TestExecutionListener[org.springframework.test.context.web]时捕获异常。ServletTestExecutionListener@cb6c1e9]准备测试实例[com]。WebApplicationTests@3d52aca]
java.lang.IllegalStateException:未能加载ApplicationContext
在org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)~[spring-test-4.3.14.RELEASE.jar:4.3.14.RELEASE]
... 省略了一些框架
原因:org.springframework.beans.factory.unsatifiedDependencyException:创建名为“aService”的bean时出错:通过字段“ctSecurityUtils”表示的未满足的依赖关系;嵌套异常为org.springframework.beans.factory.unsatifiedpendencyException:创建名为“ctSecurityUtils”的bean时出错:通过字段“arService”表示未满足的依赖关系;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“arService”的bean时出错:调用init方法失败;嵌套异常为org.springframework.orm.jpa.JpaSystemException:无法获取JDBC连接;嵌套异常为org.hibernate.exception.genericjdbception:无法获取JDBC连接
在org.springframework.beans.factory.annotation.AutoWiredNotationBeanPostProcessor$AutoWiredFeldElement.inject(AutoWiredNotationBeanPostProcessor.java:588)~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
... 省略了一些框架
原因:org.springframework.beans.factory.UnsatifiedDependencyException:创建名为“ctSecurityUtils”的bean时出错:通过字段“arService”表示的未满足的依赖关系;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“arService”的bean时出错:调用init方法失败;嵌套异常为org.springframework.orm.jpa.JpaSystemException:无法获取JDBC连接;嵌套异常为org.hibernate.exception.genericjdbception:无法获取JDBC连接
在org.springframework.beans.factory.annotation.AutoWiredNotationBeanPostProcessor$AutoWiredFeldElement.inject(AutoWiredNotationBeanPostProcessor.java:588)~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
... 省略了一些框架
原因:org.springframework.beans.factory.BeanCreationException:创建名为“arService”的bean时出错:调用init方法失败;嵌套异常为org.springframework.orm.jpa.JpaSystemException:无法获取JDBC连接;嵌套异常为org.hibernate.exception.genericjdbception:无法获取JDBC连接
在org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:137)~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
... 省略了一些框架
原因:org.springframework.orm.jpa.JpaSystemException:无法获取JDBC连接;嵌套异常为org.hibernate.exception.genericjdbception:无法获取JDBC连接
在org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:333)~[spring-orm-4.3.14.RELEASE.jar:4.3.14.RELEASE]
... 省略了一些框架
原因:org.hibernate.exception.genericjdbception:无法获取JDBC连接
在org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
... 省略了一些框架
原因:org.apache.commons.dbcp.SQLNestedException:无法创建PoolableConnectionFactory(URL格式错误;必须是“jdbc:h2:{.| mem:}[name]|[file:]fileName{tcp | ssl}:[/]server[:port]/name}[;key=value…]”,但是是“jdbc:h2 mem db:db|name(test”[90046-196])
在org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)~[commons-dbcp-1.4.jar:1.4]
... 省略了一些框架
原因:org.h2.jdbc.JdbcSQLException:URL格式错误;必须是“jdbc:h2:{.|mem:}[name]|[file:]fileName{tcp | ssl}:[/]server[:port][,server2[:port]]/name}[;key=value…]”,但必须是“jdbc:h2:mem:db|name_test”[90046-196]
在org.h2.message.DbException.getJdbcSQLException(DbException.java:345)~[h2-1.4.196.jar:1.4.196]
... 省略了一些框架

如何修复它?

通过试错法,我发现连接字符串中的这条语句导致了错误

\\;SET SCHEMA db_name_test
没有密码