已解决,供参考 使用pagehelper、driud遇到错误

新配置spring boot项目,尝试使用了driud以及pagehelper的分页,但是我发现经常报错。错误参见下方。

发现错误出现的情况是  刚开始运行并且数据库没有修改时,那么每次分页查询可以得到正确的结果。

但是在新增数据后,马上再进行分页查询,就会报错了。

参考https://www.cnblogs.com/both-eyes/p/11066937.html

似乎解决了问题,但具体原因逻辑我还没有清楚。

附上我的全部配置

#下面是连接池的一些配置
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
#连接池配置
spring.datasource.initialSize=5
spring.datasource.minIdle=5
spring.datasource.maxActive=20
#连接等待超时时间
spring.datasource.maxWait=60000
#配置隔多久进行一次检测(检测可以关闭的空闲连接)
spring.datasource.timeBetweenEvictionRunsMillis=60000
#配置连接在池中的最小生存时间
spring.datasource.minEvictableIdleTimeMillis=300000
spring.datasource.validationQuery=SELECT 1 FROM DUAL
spring.datasource.testWhileIdle=true
spring.datasource.testOnBorrow=false
spring.datasource.testOnReturn=false
# 打开PSCache,并且指定每个连接上PSCache的大小
spring.datasource.poolPreparedStatements=true
spring.datasource.maxPoolPreparedStatementPerConnectionSize=20
# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
spring.datasource.filters=stat,wall,slf4j
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
spring.datasource.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000

#解决超时错误尝试  下面这两个配置,可以在每次连接的时候判断一些连接是否有效 https://www.cnblogs.com/both-eyes/p/11066937.html
spring.datasource.druid.test-on-borrow=true
spring.datasource.druid.test-while-idle=true

 

 

2020-05-15 11:10:02.410 ERROR 540 --- [nio-8080-exec-5] druid.sql.Statement                      : {conn-10013, pstmt-20012} execute error. SELECT count(0) FROM user_info

com.mysql.cj.jdbc.exceptions.CommunicationsException: The last packet successfully received from the server was 24,599 milliseconds ago. The last packet sent successfully to the server was 24,625 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.
  

你可能感兴趣的:(spring,boot)