测试代码
@Autowired
private IProductBizService productBizService;
@Test
public void t4(){
BuyItem buyItem = new BuyItem();
buyItem.setGtin("999");
buyItem.setExpireDate(DateUtil.offsetDay(new Date(),90));
productBizService.test(buyItem);
}
第一层service实现
@Service
@Slf4j
public class ProductBizServiceImpl implements IProductBizService {
@Autowired
private IMyTransactional myTransactional;
@Override
public void test(BuyItem buyItem) {
myTransactional.saveTransactional(buyItem);
}
}
第二层事务层实现
@Service
public class IMyTransactionalImpl implements IMyTransactional {
@Autowired
private BuyItemMapper buyItemMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public void saveTransactional(BuyItem buyItem){
buyItemMapper.insert(buyItem);
throw new RuntimeException("11111111111111");
}
}
参考链接