最近 项目 线上 环境 偶尔 爆 如下 异常org.springframework.transaction.TransactionSystemException: Could not roll back                                                                                                  JDBC transaction; nested exception is java.sql.SQLException: Closed Connection
用的是 dbcp连接池各位可遇到类似 的情况呢?怎么解决呢?

解决方案 »

  1.   

    1。 connection已关闭。
    2。但报出的异常也许是其它原因造成的,
    3。可能是你的commit的connection的rollback的根本就是同一个。
    4。也有可能是说你可能线程里不安全。
      

  2.   

    刚才第三点我少打了一个字可能是你的commit的connection的rollback的根本就是同一个。
      

  3.   

    你采用spring的事务进行管理,应该是和配置有关系。发下配置文件吧!
      

  4.   

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
                http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd
                http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
                http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
    <aop:aspectj-autoproxy proxy-target-class="true"/> <aop:config proxy-target-class="false">
    <aop:advisor id="managerTx" advice-ref="txAdvice"
    pointcut="execution(* *..service..*ServiceImpl.*(..))" order="0" />
    </aop:config>
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
    <tx:method name="*" propagation="NESTED"/>
            </tx:attributes>
    </tx:advice></beans>
    以上 是 事务 配置  
      

  5.   

    汗。算了我给你发个我平常用的吧。是针对与hibernate的。<?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
    http://www.springframework.org/schema/aop 
    http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
    <!-- 定义数据源Bean,使用C3P0数据源实现 -->
    <bean id="dataSource"
    class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close">
    <!-- 指定连接数据库的驱动 -->
    <property name="driverClass" value="com.mysql.jdbc.Driver" />
    <!-- 指定连接数据库的URL -->
    <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/数据库名称" />
    <!-- 指定连接数据库的用户名 -->
    <property name="user" value="root" />
    <!-- 指定连接数据库的密码 -->
    <property name="password" value="" />
    <!-- 指定连接数据库连接池的最大连接数 -->
    <property name="maxPoolSize" value="40" />
    <!-- 指定连接数据库连接池的最小连接数 -->
    <property name="minPoolSize" value="1" />
    <!-- 指定连接数据库连接池的初始化连接数 -->
    <property name="initialPoolSize" value="1" />
    <!-- 指定连接数据库连接池的连接的最大空闲时间 -->
    <property name="maxIdleTime" value="20" />
    </bean> <!-- 定义Hibernate的SessionFactory -->
    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <!-- 依赖注入数据源,注入正是上面定义的dataSource -->
    <property name="dataSource" ref="dataSource" />
    <!-- mappingResouces属性用来列出全部映射文件 -->
    <property name="mappingResources">
    <list>
    <!-- 以下用来列出Hibernate映射文件 -->
    <value>包名/xxx.hbm.xml</value> </list>
    </property>
    <!-- 定义Hibernate的SessionFactory的属性 -->
    <property name="hibernateProperties">
    <props>
    <!-- 指定数据库方言 -->
    <prop key="hibernate.dialect">
    org.hibernate.dialect.MySQLInnoDBDialect
    </prop>
    <!-- 是否根据需要每次自动创建数据库 -->
    <prop key="hibernate.hbm2ddl.auto">update</prop>
    <!-- 显示Hibernate持久化操作所生成的SQL -->
    <prop key="hibernate.show_sql">true</prop>
    <!-- 将SQL脚本进行格式化后再输出 -->
    <prop key="hibernate.format_sql">true</prop>
    </props>
    </property>
    </bean> <!-- 配置Hibernate的局部事务管理器,使用HibernateTransactionManager类 -->
    <!-- 该类实现PlatformTransactionManager接口,是针对Hibernate的特定实现-->
    <bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <!-- 配置HibernateTransactionManager时需要依注入SessionFactory的引用 -->
    <property name="sessionFactory" ref="sessionFactory" />
    </bean> <!-- 配置事务切面Bean,指定事务管理器 -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
    <!-- 用于配置详细的事务语义 -->
    <tx:attributes>
    <!-- 所有以'xxx'开头的方法是read-only的 -->
    <tx:method name="xxx*" read-only="true" />
    <!-- 其他方法使用默认的事务设置 -->
    <tx:method name="*" />
    </tx:attributes>
    </tx:advice> <aop:config>
    <!-- 配置一个切入点,匹配某某某包下
    所有以Impl结尾的类的所有方法的执行 -->
    <aop:pointcut id="leePointcut"
    expression="execution(* 包名.*Impl.*(..))" />
    <!-- 指定在leePointcut切入点应用txAdvice事务切面 -->
    <aop:advisor advice-ref="txAdvice" pointcut-ref="leePointcut" />
    </aop:config>
    </beans>
      

  6.   

    看不出来啥我 是dbcp而已好像配置更你这个 差不多 
      

  7.   

    可能是你的commit的connection的 rollback的根本就是不同一个。
    也有可能是说你可能线程里不安全。