我的应用程序使用 Spring+Hibernate+MySQL 运行良好,但有时我会遇到这些错误
错误:
could not execute query; nested exception is org.hibernate.exception.JDBCConnectionException: could not execute query
我正在 tomcat - 7 版本上运行我的应用程序
因此,如果我超过一段时间不使用该应用程序,我会收到此错误,我不知道时间,如果我重新启动我的应用程序,那么我可以正常工作,我不会收到任何错误
我的 database.xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
</beans>
上面的配置有没有什么问题我需要修改才能解决这个问题
最佳答案
根据 this回答,你必须把mysql Connector/Driver放在Tomcat/lib
里而不是war里。每次部署 war 时,都会创建连接器/驱动程序,有时垃圾收集器无法删除它们,这将导致内存泄漏。
关于java - 获取 org.hibernate.exception.JDBCConnectionException : could not execute query in Spring application after some time of application working fine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33755723/