当整个功能运行良好时偶尔会发生此错误。但是这种异常可能会不时抛出。我找到了一个将mysql-connector-java-5.1.24.jar
复制到tomcat/lib
文件夹的解决方案,而此错误将消失。如果没有这个,Web服务器最终将创建与数据库的过多连接。
任何人都可以帮忙解释为什么会发生这种情况,为什么要将jar从webapps
移到tomcat/lib
?
### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: No suitable driver found for jdbc:mysql://*:3399/*?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&mysqlEncoding=utf-8
### The error may exist in net/ebaolife/tpa/mapper/DivisionalCaseMapper.java (best guess)
### The error may involve net.ebaolife.tpa.mapper.DivisionalCaseMapper.selectCount
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: No suitable driver found for jdbc:mysql://*:3399/*?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&mysqlEncoding=utf-8
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:79)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:447)
at com.sun.proxy.$Proxy945.selectMap(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectMap(SqlSessionTemplate.java:183)
at org.apache.ibatis.binding.MapperMethod.executeForMap(MapperMethod.java:174)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:70)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53)
at com.sun.proxy.$Proxy968.selectCount(Unknown Source)
at net.ebaolife.tpa.service.impl.DivisionalCaseServiceImpl.selectCount(DivisionalCaseServiceImpl.java:329)
at net.ebaolife.tpa.service.impl.DivisionalCaseServiceImpl$$FastClassBySpringCGLIB$$605de877.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)
at net.ebaolife.tpa.service.impl.DivisionalCaseServiceImpl$$EnhancerBySpringCGLIB$$e8a8ee89.selectCount(<generated>)
at net.ebaolife.tpa.web.controller.WebSocketController$1.run(WebSocketController.java:37)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.ibatis.exceptions.PersistenceException: