错误信息:
Caused by: java.sql.SQLException: connection holder is null at com.alibaba.druid.pool.DruidPooledConnection.checkState(DruidPooledConnection.java:1085) at com.alibaba.druid.pool.DruidPooledConnection.getMetaData(DruidPooledConnection.java:825) at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:285)
原因:
#是否自动回收超时连接 removeAbandoned = true
#超时时间(以秒数为单位) removeAbandonedTimeout = 1800
数据库连接超过了removeAbandonedTimeout规定的时间没有主动关闭,连接池启用自我保护机制把连接关了,当程序再使用这个连接就会报错。(同一个连接超时被强制回收了)
1.一个事务内,程序处理时间太久,大的事务。
2.程序异常代码,长时间用的同一个数据库连接。
解决方案:
removeAbandoned和removeAbandonedTimeout是为了防止连接泄漏,可以根据需要调整超时时间。
1. removeAbandoned设置为false
2.将removeAbandonedTimeout设置比较大