亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

單元測試時Junit報錯,求解

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.? Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
### The error may exist in file [D:\apache-maven-3.3.9Project\Projects\seckill\target\classes\mappers\seckillDAO.xml]
### The error may involve cn.jr.dao.SeckillDAO.queryById
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
?at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)
?at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
?at com.sun.proxy.$Proxy16.selectOne(Unknown Source)
?at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:166)
?at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:82)
?at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53)
?at com.sun.proxy.$Proxy17.queryById(Unknown Source)
?at cn.jr.dao.SeckillDAOTest.testQueryById(SeckillDAOTest.java:34)
?at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
?at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
?at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
?at java.lang.reflect.Method.invoke(Method.java:498)
?at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
?at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
?at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
?at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
?at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
?at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
?at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
?at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
?at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
?at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
?at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
?at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
?at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
?at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
?at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
?at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
?at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
?at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
?at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
?at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
?at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
?at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
?at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
?at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
?at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.? Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
### The error may exist in file [D:\apache-maven-3.3.9Project\Projects\seckill\target\classes\mappers\seckillDAO.xml]
### The error may involve cn.jr.dao.SeckillDAO.queryById
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
?at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
?at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150)
?at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
?at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:77)
?at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
?at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
?at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
?at java.lang.reflect.Method.invoke(Method.java:498)
?at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433)
?... 35 more
Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
?at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
?at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:82)
?at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:68)
?at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:336)
?at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:84)
?at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62)
?at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324)
?at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
?at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
?at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83)
?at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)
?... 42 more
Caused by: java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
?at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
?at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:65)
?at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:527)
?at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
?at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
?at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
?... 52 more
Caused by: com.mchange.v2.resourcepool.TimeoutException: A client timed out while waiting to acquire a resource from com.mchange.v2.resourcepool.BasicResourcePool@909217e -- timeout at awaitAvailable()
?at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1317)
?at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
?at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
?at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
?... 55 more


正在回答

3 回答

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://10.1.60.43:3306/seckill?useUnicode=true&characterEncoding=utf8
jdbc.username=root
jdbc.password=123456

都加個jdbc的前綴

0 回復 有任何疑惑可以回復我~
#1

慕粉4207257 提問者

我都在資源文件中加了/(ㄒoㄒ)/~~
2017-03-03 回復 有任何疑惑可以回復我~
#2

慕粉4207257 提問者

<property name="driverClass" value="${jdbc.driver}"/> <property name="jdbcUrl" value="${jdbc.url}"/> <property name="user" value="${jdbc.user}"/> <property name="password" value="${jdbc.password}"/>
2017-03-03 回復 有任何疑惑可以回復我~
#3

慕粉4207257 提問者

非常感謝!原來是我打錯了url
2017-03-03 回復 有任何疑惑可以回復我~
#4

飛翔的豬OVO

請問為什么加jdbc后就好了呢
2017-03-14 回復 有任何疑惑可以回復我~
查看1條回復

加了也沒用啊

0 回復 有任何疑惑可以回復我~

為什么,我也是,在前面加jdbc的前綴才是對的,但是老師的每加,以前我做也沒加,也行。這是什么原因呢?

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

單元測試時Junit報錯,求解

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號