方法A:
classA
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void testA(Student student) {
......
try {
classB.testB(student);
} catch (CustomException e) {
log.warn("失败,原因:" + e.getMessage());
} catch (ParamException e) {
log.warn("失败,原因:" + e.getMessage());
} catch (Exception e) {
log.error("失败,原因:" + e.getMessage(), e);
}
}
classB
@Override
@Transactional(rollbackFor=Exception.class,propagation=Propagation.REQUIRES_NEW)
public void testB(Student student) {
try{
......
} catch (CustomException e) {
throw e;
} catch (ParamException e) {
throw e;
} catch (Exception e) {
log.error("出错:" + e.getMessage(), e);
}
}
问题:
org.springframework.transaction.UnexpectedRollbackException: Transaction rolled back because it has been marked as rollback-only
该问题偶发,什么情况下会抛出此异常?求解
一般是事务嵌套的问题,就你现在的代码,一般不会出现这个问题的
