zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    [小试牛刀]部署在IDEA的JFinal 3.0 demo
    使用myBase Desktop来管理电脑上的资料
    用URLGather来管理和保存你的页面
    查看Json的结构及内容:JsonViewerPackage
    有用的2个 Windows 下批处理文件(bat文件):
    在Eclipse-jee-neon中配置Hibernate(jbosstools)
    [Eclipse的Maven项目搭建,仅为测试Maven功能]如何在Eclipse下搭建Maven项目
    在 Windows 中配置Maven:
    你的package包名有问题!
    Workflow Builder 2.6.3 Certified on Windows 10 for EBS 12.x
  • 原文地址:https://www.cnblogs.com/zt007/p/14961865.html
Copyright © 2011-2022 走看看