gpt4 book ai didi

mysql - Spring MVC 和 Hibernate 在 8 小时后停止工作

转载 作者:太空宇宙 更新时间:2023-11-03 11:37:13 24 4
gpt4 key购买 nike

以下 xml 配置文件在 8 小时不活动后停止工作并出现此错误:

错误:已经关闭。

25-may-2017 8:45:23 org.apache.catalina.core.StandardWrapperValve invoke

Servlet.service() for servlet [dispatcher] in the context with path [/system] threw exception [Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionException: JDBC begin transaction failed: ] with root cause:
java.net.SocketException: **Software caused connection abort: recv failed**

配置文件如下:

<context:component-scan base-package="es.company.system.persistence" />

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="es.mypackage.model"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.show_sql">false</prop>
</props>
</property>
</bean>

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">

<property name="connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="connection.url" value="jdbc:mysql://localhost:3306/system" />
<property name="connection.username" value="???" />
<property name="connection.password" value="???" />

<property name="hibernate.c3p0.min_size" value="5" />
<property name="hibernate.c3p0.max_size" value="20" />
<property name="hibernate.c3p0.timeout" value="1800"/>
<property name="hibernate.c3p0.max_statements" value="50" />

<property name="hibernate.c3p0.testConnectionOnCheckout" value="true" />

<property name="hibernate.c3p0.privilegeSpawnedThreads" value="true" />
<property name="hibernate.c3p0.contextClassLoaderSource" value="library" />

</bean>

<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<bean id="persistenceExceptionTranslationPostProcessor"
class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />

<tx:annotation-driven transaction-manager="transactionManager" />

我目前正在使用 Spring MVC 4.3.8 和 Hibernate 4.1.9。用于 MySQL 的 C3P0 连接池。我认为使用 C3P0 可以解决这个问题,但事实并非如此。任何人都知道怎么了?

谢谢!!!

最佳答案

软件导致连接中止:接收失败 --这通常意味着存在网络错误,例如 TCP 超时。

同时为 hibernate.c3p0.timeout 设置超时参数,默认值为 0

hibernate.c3p0.timeout – When an idle connection is removed from the pool (in second). Hibernate default: 0, never expire.

设置 autoReconnect ,hibernate.c3p0.autoReconnect = true 或作为 url 连接参数:jdbc:mysql://localhost:3306/test?autoReconnect=true

添加< property name="hibernate.c3p0.preferredTestQuery">SELECT 1</property>并检查它是否记录了 c3p0 执行它(如果没有从限制为 1 的真实表中添加真实选择计数(1))。还要检查你的网络超时

关于mysql - Spring MVC 和 Hibernate 在 8 小时后停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44883878/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com