当前位置:   article > 正文

The last packet successfully received from the server was milliseconds ago

the last packet successfully received from the server was 1 milliseconds ago

查阅了一下,网上一般的做法有以下几种:

修改mysql的wait_timeout,修改spring数据源配置,增加maxWait(要比数据库wait_timeout小)、testOnBorrow=true、queryTimeout等配置,在datasource.url后面增加autoReconnect=true配置。

更新mysql-connector版本,我用的是8.0.28

更新jdk版本,如jdk1.7升级到jdk1.8

尝试过上面的几个方法都没办法解决。

从报错信息来看,这里设置的超时是10000毫秒,然后把mysql-connector源码下载下来debug了一下,发现有socketTimeout参数的值正好是10000,然后尝试在spring数据源配置上增加次配置依旧不行。

最后在datasource.url后面socketTimeout参数配置,重启测试发现能被正确识别,到此问题解决。

下面是druid和datasource的配置,仅供参考

druid:
  initial-size: 5
  min-idle: 2
  maxActive: 10
  maxWait: 60000
  timeBetweenEvictionRunsMillis: 60000
  minEvictableIdleTimeMillis: 300000
  validationQuery: SELECT 1 FROM DUAL
  testWhileIdle: true
  testOnBorrow: false
  testOnReturn: false
  poolPreparedStatements: true
  maxPoolPreparedStatementPerConnectionSize: 20
  filters: stat,slf4j
  connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
  
datasource:
  driver-class-name: com.mysql.cj.jdbc.Driver
  url: jdbc:mysql://localhost:3306/test?useUnicode=true&useSSL=false&allowLoadLocalInfile=false&autoReconnect=true&failOverReadOnly=false&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2B8&connectTimeout=1000&socketTimeout=30000
  username: root
  password: 123456

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/爱喝兽奶帝天荒/article/detail/1014656
推荐阅读
相关标签
  

闽ICP备14008679号