1. 程式人生 > >myBatis連接MySQL報異常:No operations allowed after connection closed.Connection was implicitly closed

myBatis連接MySQL報異常:No operations allowed after connection closed.Connection was implicitly closed

csdn spa logs action env target details 默認 col

網站運行一個晚上,早上來上班,發現報錯:

### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.

網上查了下,由於使用了默認配置,空閑超過8小時,自動斷開該連接

我使用的是mybatis的默認連接池,於是把該配的,都配置上。datasource的屬性,可參考mybatis官方文檔

        <environment id="env_stg"
> <transactionManager type="JDBC" /> <dataSource type="POOLED"> <property name="driver" value="${driver}" /> <property name="url" value="${url_stg}" /> <property name="username" value="${username}" />
<property name="password" value="${password}" /> <property name="poolMaximumActiveConnections" value="20"/> <property name="poolMaximumIdleConnections" value="5"/> <!-- MySQLNonTransientConnectionException: No operations allowed after connection closed
--> <property name="poolPingQuery" value="select 1"/> <property name="poolPingEnabled" value="true"/> <!-- 對於空閑的連接一個小時檢查一次 --> <property name="poolPingConnectionsNotUsedFor" value="3600000"/> </dataSource> </environment>

參考:http://fengbin2005.iteye.com/blog/1906488

很棒的一篇文章:《深入理解mybatis原理》 Mybatis數據源與連接池

myBatis連接MySQL報異常:No operations allowed after connection closed.Connection was implicitly closed