切面重试,事务回滚生效

本文介绍了如何在MacOS环境下,使用Visual Studio Code(VSCode)进行编程时,配置切面重试和事务回滚的详细步骤。通过设置编辑器的相关插件和配置,确保在遇到异常时能够自动进行重试操作,并有效管理事务,保证数据一致性。
摘要由CSDN通过智能技术生成
@Aspect
@Component
public class TryAgainAspect {

    @Pointcut("@annotation(com.smartErp.service.common.annotation.TryAgain)")
    public void tryMore() {}

    @Around("tryMore()")
    public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
        Method method = ((MethodSignature) pjp.getSignature()).getMethod();
        TryAgain tryAgain = method.getAnnotation(TryAgain.class);
        int numAttempts = 0;
        int maxRetries = tryAgain.maxAttemps();
        do {
            numAttempts++;
            Object savepoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint();//设置回滚点
            try {
                return pjp.proceed();
            } catch (BizException ex) {
                TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savepoint);
                if (!ex.getEnumInterface().getCode().equals(BaseExceptionCode.TRY_AGAIN.getCod
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值