myBatis连接MySQL报异常:No operations allowed after connection closed.Connection was implicitly closed(示例代

Posted 寻坑者

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了myBatis连接MySQL报异常:No operations allowed after connection closed.Connection was implicitly closed(示例代相关的知识,希望对你有一定的参考价值。

网站运行一个晚上,早上来上班,发现报错:

### 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(示例代的主要内容,如果未能解决你的问题,请参考以下文章

mysql链接出现: No operations allowed after statement closed.

MySQL:No operations allowed after connection closed错误原因及解决

ssh报错No operations allowed after connection closed.Connection was implicitly clos

mysql数据库连接不定时报错,no operations allowed...

Spring Boot连接MySQL长时间不连接后报错`com.mysql.cj.core.exceptions.ConnectionIsClosedException: No operations

SpringBoot 连接kafka ssl 报 CertificateException: No subject alternative names present 异常解决