问题一:
在项目中集成druid项目中,发现错误日志中频繁的出现如下错误信息:
08:01:59.035 [http-nio-9201-exec-4] WARN c.a.d.p.DruidAbstractDataSource - [testConnectionInternal,1494] - discard long time none received connection.,jdbcUrl : jdbc:MysqL://xxxx:3306/ry-cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8,version : 1.2.8,lastPacketReceivedIdleMillis : 3506735
这类的错误。虽然是警告没有影响业务。但看着实在难受。
分析:经过排查发现是druid版本导致的异常,这里用的是
<druid.version>1.2.8</druid.version>
在1.2.2及以前版本并未出现如此异常。而在其以上版本均存在此问题,下面就来分析一下异常原因及解决方案。
在源码中会找到这么一段代码:
public void configfromproperties(properties properties) {
string property = properties.getproperty("druid.MysqL.usepingmethod");
if ("true".equals(property)) {
setusepingmethod(true);
} else if ("false".equals(property)) {
setusepingmethod(false);
}
}
可以看到获取了配置文件 druid.MysqL.usepingmethod这个属性,为true还是为false进行输出的。那么我们可以在启动时进行配置。
解决一:在启动程序时在运行参数中增加:-ddruid.MysqL.usepingmethod=false。
解决三:配置类中进行设置为false
因为我这里用的是nacos,所以以上我均可以不采用,直接使用nacos配置如下
dynamic:
druid:
initial-size: 5
min-idle: 5
maxActive: 20
maxWait: 60000
timeBetweenevictionRunsMillis: 60000
minevictableIdleTimeMillis: 300000
validationQuery: SELECT 1 FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
MysqL:
usePingMethod: false
maxPoolPreparedStatementPerConnectionSize: 20
filters: stat,slf4j
connectionProperties: druid.stat.mergesql\=true;druid.stat.slowsqlMillis\=5000
添加上 MysqL: usePingMethod: false
再次启动可以解决。
------------------------------------------------------------------------------------------------------------
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。