总结:
方法A调用方法B:
1、如果只有A加@Transactional注解;则AB在同一事务中,任意异常都回滚;
2、如果只有B加@Transactional注解;AB方法为同一类,事务失效任意异常都不回滚;AB不同类,只有B有事务且只有B异常B才回滚;
测试:
@RestController @RequestMapping("test") @Slf4j public class TestController { @GetMapping("/test") public R test() { testA(); return R.success(); } @Autowired ResourceFileService resourceFileService; public void testA() { OcResourceFileEntity entity = new OcResourceFileEntity(); entity.setApplyId("11111"); resourceFileService.save(entity); testB(); } @Transactional(rollbackFor = Exception.class) public void testB() { OcResourceFileEntity entity = new OcResourceFileEntity(); entity.setApplyId("22222"); resourceFileService.save(entity); int i = 1/0; } }
标签:事务,调用,Transactional,回滚,entity,OcResourceFileEntity,AB,public From: https://www.cnblogs.com/min225016/p/16806147.html