一、基本概念
二、 嵌套事务示例
2.1、Propagation.REQUIRED+Propagation.REQUIRES_NEW
packagedxz.demo1;
@Servicepublic class ServiceAImpl implementsServiceA {
@AutowiredprivateServiceB serviceB;
@AutowiredprivateVcSettleMainMapper vcSettleMainMapper;
@Override
@Transactional(propagation= Propagation.REQUIRED, readOnly = false)public voidmethodA() {
String id= IdGenerator.generatePayId("A");
VcSettleMain vc=buildModel(id);
vcSettleMainMapper.insertVcSettleMain(vc);
System.out.println("ServiceAImpl VcSettleMain111:" +vc);
serviceB.methodB();
VcSettleMain vc2=buildModel(id);
vcSettleMainMapper.insertVcSettleMain(vc2);
System.out.println("ServiceAImpl VcSettleMain22222:" +vc2);
}privateVcSettleMain buildModel(String id) {
VcSettleMain vc= newVcSettleMain();
vc.setBatchNo(id);
vc.setCreateBy("dxz");
vc.setCreateTime(LocalDateTime.now());
vc.setTotalCount(11L);
vc.setTotalMoney(BigDecimal.ZERO);
vc.setState("5");returnvc;
}
}
ServiceB
packagedxz.demo1;
@Servicepublic class ServiceBImpl implementsServiceB {
@AutowiredprivateVcSettleMainMapper vcSettleMainMapper;
@Override
@Transactional(propagation= Propagation.REQUIRES_NEW, readOnly = false)public voidmethodB() {
String id= IdGenerator.generatePayId("B");
VcSettleMain vc=buildModel(id);
vcSettleMainMapper.insertVcSettleMain(vc);
System.out.println("---ServiceBImpl VcSettleMain:" +vc);
}
}
controller
packagedxz.demo1;
@RestController
@RequestMapping("/dxzdemo1")
@Api(value= "Demo1", descri