<dataSource type="POOLED"> <property name="driver" value="${driver}" /> <property name="url" value="${url}" /> <property name="username" value="${username}" /> <property name="password" value="${password}" /> <property name="poolMaximumActiveConnections" value="900" /><!-- 同一时间内最大连接数 --> <property name="poolMaximumIdleConnections" value="100" /><!-- 连接最大空闲数目 --> <property name="poolMaximumCheckoutTime" value="10000" /><!-- 连接被每个任务占用的最大时间 --> <property name="poolTimeToWait" value="5000" /><!-- 连接池中无可用连接时,线程的等待时间 --> <property name="poolPingQuery" value="select now()" /> <property name="poolPingEnabled" value="true" /> </dataSource>上面是MapperConfig配置的数据源。建立mysql连接的时候也加了autoReconnect,如下:
Reader reader = Resources.getResourceAsReader(DATA_MAPPER_FILE); DBConfig dbConfig = SystemConfig.getDataDBConfig(); Properties properties = new Properties(); properties.put("driver", "com.mysql.jdbc.Driver"); String url = "jdbc:mysql://" + host + ":" + port + "/" + dbName + "?autoReconnect=true&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true"; properties.put("url", url); properties.put("username", "usr"); properties.put("password", "password"); dataSessionFactory = new SqlSessionFactoryBuilder().build(reader, properties); reader.close();
178262497 [pool-3-thread-300] WARN org.apache.ibatis.datasource.pooled.PooledDataSource - Execution of ping query 'select now()' failed: The last packet successfully received fr
om the server was 133,200,879 milliseconds ago. The last packet sent successfully to the server was 133,200,879 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 timeout
s, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
mysql5.5还是5.6+autoReconnect已经没用了。
你可以检查一下网络配置和数据库的timeout配置。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。