Caused by: com.alibaba.druid.pool.DataSourceClosedException: dataSource already closed
报错场景:spring boot+mybatis,线程池执行批量任务。springboot正常启动后,定时任务中数据库查询报错。报错信息如下:


1 Caused by: org.apache.ibatis.exceptions.PersistenceException:
2 ### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection;
3 nested exception is com.alibaba.druid.pool.DataSourceClosedException: dataSource already closed at Wed Jun 30 17:31:57 GMT+08:00 2021
4 ### The error may exist in URL [jar:file:/home/xxx/xxx/xxx-1.0.jar!/BOOT-INF/lib/common-1.0.jar!/mapper/basedata_mapper/xxxMapper.xml]
5 ### The error may involve com.xxx.common.basedata.dao.xxxTaskDao.getListByCode
6 ### The error occurred while executing a query
7 ### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.alibaba.druid.pool.DataSourceClosedException: dataSource already closed at Wed Jun 30 17:31:57 GMT+08:00 2021
8 at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
9 at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150)
10 at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
11 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
12 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
13 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
14 at java.lang.reflect.Method.invoke(Method.java:498)
15 at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433)
16 ... 15 common frames omitted
报错信息
解决:
多线程批量处理的时候只需要在service方法上加上@transactional(rollbackFor = Exception.class)就行了,mybatis就不会每次执行完sql后closing sql session了
Sign up for free
参考:
https://github.com/alibaba/druid/issues/1625
Caused by: com.alibaba.druid.pool.DataSourceClosedException: dataSource already closed的更多相关文章
- 配置DruidDataSource参考(com.alibaba.druid.pool.DruidDataSource)
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-met ...
- 【Druid】 阿里巴巴推出的国产数据库连接池com.alibaba.druid.pool.DruidDataSource
阿里巴巴推出的国产数据库连接池,据网上测试对比,比目前的DBCP或C3P0数据库连接池性能更好 简单使用介绍 Druid与其他数据库连接池使用方法基本一样(与DBCP非常相似),将数据库的连接信息 ...
- com.alibaba.druid.pool.DruidDataSource : {dataSource-2} init error
这几天准备写一个项目,其中的整合druid的时候,发现出现了下面这个错误.找了好久都没有找到.网上的各种解决方法都不对. 2018-11-07 16:26:28.940 INFO 19684 --- ...
- 【spring boot】集成了druid后,同样的mybatis模糊查询语句出错Caused by: com.alibaba.druid.sql.parser.ParserException: syntax error, error in :'name LIKE '%' ? '%'
druid版本是 <!-- https://mvnrepository.com/artifact/com.alibaba/druid 数据库连接池--> <dependency> ...
- 数据库链接失败错误ERROR com.alibaba.druid.pool.DruidDataSource - {dataSource-1} init error解决
用java -jar启动之后,只要一访问数据库就报错,错误信息如下: 文字如下: 2019-07-02 10:25:12.220 ---> [http-nio-8080-exec-1] ---& ...
- 阿里巴巴高新能数据源com.alibaba.druid.pool.DruidDataSource的jar包配置
aspectjweaver-1.7.4.jar druid-0.2.9.jar 两个包,用于提供com.alibaba.druid.pool.DruidDataSource
- Could not open JDBC Connection for transaction; nested exception is com.alibaba.druid.pool.GetConnection
Could not open JDBC Connection for transaction; nested exception is com.alibaba.druid.pool.GetConnec ...
- Javassm连接数据库报错129 ERROR [com.alibaba.druid.pool.DruidDataSource] - {dataSource-1} init error
Javassm连接数据库报错129 ERROR [com.alibaba.druid.pool.DruidDataSource] - {dataSource-1} init error 发现jdbc这 ...
- ERROR 14856 --- [reate-882003853] com.alibaba.druid.pool.DruidDataSource : create connection error, url: jdbc:mysql://localhost:3306/xhb?useUnicode=true&characterEncoding=UTF-8, errorCode 1045, sta
ERROR 14856 --- [reate-882003853] com.alibaba.druid.pool.DruidDataSource : create connection error, ...
- com.alibaba.druid.pool.DruidPooledConnection cannot be cast to oracle.jdbc.OracleConnection 异常解决办法
java.lang.ClassCastException: com.alibaba.druid.pool.DruidPooledConnection cannot be cast to oracle. ...
随机推荐
- [转帖]Jmeter学习笔记(十七)——jmeter目录结构
原文链接:http://www.cnblogs.com/zichuan/p/6938772.html 一.bin目录examples: 目录中有CSV样例 jmeter.bat windows ...
- [转帖]1.IPtable基础命令总结
https://www.cnblogs.com/kcxg/p/10350870.html 规则查询 #查看对应表中的所有规则 iptables -t 表名 -L #查看表的指定链中的规则 iptabl ...
- [转帖]一个小技巧解决笔记本HDMI接口失灵
https://baijiahao.baidu.com/s?id=1738289993804283647&wfr=spider&for=pc 现如今笔记本的接口是越来越多,哪怕是标 ...
- UnixBench的简单测试与验证
UnixBench的简单测试与验证 目标 飞腾2000+ (物理机和虚拟机) Intel Golden 6170 物理机 Intel Golden 5218 虚拟机 Gold 5218 CPU @ 2 ...
- redis 6源码解析之 dict
edis源码的dict.c主要实现了基于hash表的操作,如增删改查,对哈希表大小的扩容和缩容,以及对哈希表的rehash和增量rehash等.在源码的dictScan函数中,非常巧妙精美地实现了对哈 ...
- vue中父传子props的使用
第一种 传递一个数组 props:["cont"] 第二种 传递一个对象 props:{ uploadOption:{ type:Object, 参数类型必须是一个对象 requi ...
- 从零开始配置vim(21)——会话管理
很多代码编辑器都有这么一个功能,重新进入编辑器之后能恢复上次打开的所有文件,窗口布局,有的甚至是上次设置的一些配置.那么vim是否也可以实现这样的功能呢?答案是肯定的.使用vim自带的会话管理和 vi ...
- vim 从嫌弃到依赖(4)—— .命令
通过之前几篇文章的介绍,如果各位小伙伴能够勤加练习,并在日常工作上经常使用,那么相信那些内容已经会对工作效率的提升产生好的影响.但是如果那些就是vim的全部的话,我们也就没那么大的必要花这么大的精力来 ...
- Pdfium.Net.Free 一个免费的Pdfium的 .net包装器--PDF预览器框选
项目地址: Pdfium.Net:https://github.com/1000374/Pdfium.Net PdfiumViewer:https://github.com/1000374/Pdfiu ...
- 《重学Java设计模式》作者开始录视频了!
作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 1. 前言 哈哈哈,终于对B站下手了! 大家好,我是小傅哥,在紧张.羞涩到适应后,哈哈哈,终于 ...