首页 > 解决方案 > 如何在自定义方面回滚事务

问题描述

这是我的代码

@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 上回滚事务?

标签: spring-bootspring-jdbc

解决方案


您可以在 @Transactional 注释中声明您希望在抛出 RuntimeException 时执行回滚:@Transactional(rollbackFor=RuntimeException.class)


推荐阅读