java - 获取 org.hibernate.exception.JDBCConnectionException : could not execute query in Spring application after some time of application working fine

标签 java mysql spring hibernate tomcat

我的应用程序使用 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/

相关文章:

java - 在android中的 Activity 后面运行一个线程

java - 使用 hibernate 时在 POJO 中使用构造函数有哪些限制?

php - 在mysql和PHP中检查一个字段是否有属性 `UNIQUE`

java - 上下文表单循环中的多个 RestTemplate 构建器

spring - Cloud Foundry 中的应用程序能够访问 Redis,即使 Redis 服务与该应用程序解除绑定(bind)也是如此

java - JPA-存储库保存 : Proceed saving after insert Constraint violation

java - 创建多个 HSQLDB 服务器数据库的最简单方法是什么?

php - 如何在 Symfony 2 中运行纯 mysql 查询?

mysql - 如何减去日期,然后将上一次运算的结果相加

java - Spring MVC 中的 HttpMessageNotWritableException : No converter found for return value of type: class java. util.HashMap