如何在定制方面回滚事务

时间:2018-09-11 05:58:08

标签: spring-boot spring-jdbc

这是我的代码

@Around("service()")
public Object serviceThreadLocalHandle(ProceedingJoinPoint joinPoint) throws Throwable{
    // joinPoint is a service instance
    Object proceed = joinPoint.proceed();
    cache = ContractCache.LOCAL_CACHE.get();
    // there i throw a exception but i can not rollback the transaction
    if(true){
       throw new RuntimeException();
    }
    return proceed;
}

那么如何在我的方面Spring Boot 1.5.8 RELEASE上回滚事务?

1 个答案:

答案 0 :(得分:0)

您可以在@Transactional批注中声明要在引发RuntimeException时执行回滚: @Transactional(rollbackFor = RuntimeException.class)