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

來源:互聯網
上載者:User

標籤:conf   ansi   html   for   bin   source   article   nts   lua   

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

### 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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.