问题描述
- spring @Transactional 事务不能回滚
-
在spring的配置文件里配置如下:<!-- enable the configuration of transactional behavior based on annotations --> <tx:annotation-driven transaction-manager="txManager"/> <!-- a PlatformTransactionManager is still required --> <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <!-- (this dependency is defined somewhere else) --> <property name="dataSource" ref="dataSource"/> </bean>
测试代码如下:
@Override @Transactional(propagation = Propagation.REQUIRED) public void saveLoginInfo(String userName, String dateString, String result) { String sql = "INSERT INTO prc_mbl_usr_usg (slsprs_id, lgn_dtm, lgn_sts ) VALUES (" + "'" + userName + "'," + "'" + dateString + "'," + "'" + result + "')"; logger.info(sql); toolsDao.insertUtils(sql); int m = 1; if (m == 1) { throw new RuntimeException(); } toolsDao.insertUtils(sql); }
抛出异常后,异常前面的insert插入的记录无法回滚,求解
解决方案
回滚后,是又插入了吧。
时间: 2024-09-24 20:24:07