Mybatis报错解决: Your driver may not support getAutoCommit() or setAutoCommit()

报错信息:

### Cause: org.apache.ibatis.transaction.TransactionException: Error configuring AutoCommit.  Your driver may not support getAutoCommit() or setAutoCommit(). Requested setting: false.  Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 82,940,457 milliseconds ago.  The last packet sent successfully to the server was 82,940,457 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.

这个错误是偶尔才发现,解决办法是在mybatis配置文件中加如下配置:

<property name="poolPingQuery" value="SELECT NOW()" />
<property name="poolPingEnabled" value="true" />

完整配置如下:



<configuration>
    
    <environments default="aaa">
        <environment id="aaa">
            <transactionManager type="JDBC" />
            <dataSource type="POOLED">
                
                <property name="poolMaximumActiveConnections" value="1000"/>
                <property name="driver" value="${jdbc.driver}" />
                <property name="url" value="${jdbc.url}" />
                <property name="username" value="${jdbc.username}" />
                <property name="password" value="${jdbc.password}" />
                <property name="poolPingQuery" value="SELECT NOW()" />
                <property name="poolPingEnabled" value="true" />
            dataSource>
        environment>
    environments>
    <mappers>
        <mapper resource="common-mapper.xml"/>
    mappers>
configuration>

你可能感兴趣的:(java,mybatis)