背景:
在执行springboot事务时发现表中数据未能正常回滚掉
猜想:
1.springboot中事务未能成功开启,可能没有引入aop导致
2.springboot中方法抛出的异常不能被事务框架正常捕获
问题定位:
代码如下
@Service
public class TestServiceImpl implements TestService {
@Autowired
private RoleMappingMapper roleMappingMapper;
@Autowired
private JdbcTemplate jdbcTemplate;
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.REPEATABLE_READ)
@Override
public void test() throws Exception {
//执行普通数据插入操作DML
RoleMappingPO roleMappingPO = new RoleMappingPO();
roleMappingPO.setCreateTime(new Date());
roleMappingPO.setRoleId(1000L);
roleMappingPO.setMappingId(1000L);
roleMappingMapper.insert(roleMappingPO);
//执行添加索引,为DDL操作
jdbcTemplate.execute("alter table t_user add index index_email (email)");
throw new Runti