事务传播方式:
1.REQUIRES_NEW
/*** * @description 方法加事务 REQUIRES_NEW ,内部方法也加事务 REQUIRES_NEW 以哪个事务为准 * @methodName testTrancNew * @date 2020/9/10 20:02 * @param * @return void * @throws */ @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) @Override public void testTrancNew() { /** * begin tran A * begin tran B * cityDataService.trancNewARequires_new() 事务传播方式 REQUIRES_NEW 不受外部方法的影响,内部买没有异常就提交成功 * commit B * insert() * trancNewBThrowException() * rollback A */ //不会回滚 cityDataService.trancNewARequires_new(); Mycity city = new Mycity(); city.setCountry("外部方法 REQUIRES_NEW"); city.setName("中国A"); mycityMapper.insert(city); //抛异常 cityDataService.trancNewBThrowException(); } //cityDataService: @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) @Override public void trancNewARequires_new() { City city = new City(); city.setCountry("内部方法 REQUIRES_NEW"); city.setName("中国A"); cityMapper.insert(city); } @Override public void trancNewBThrowException() { City city = new City(); city.setCountry("methodA"); city.setName("中国A"); int a = 4; int cc = a / 0; cityMapper.insert(city); } REQUIRES_NEW