@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
切面重试,事务回滚生效
最新推荐文章于 2022-10-23 15:35:12 发布
本文介绍了如何在MacOS环境下,使用Visual Studio Code(VSCode)进行编程时,配置切面重试和事务回滚的详细步骤。通过设置编辑器的相关插件和配置,确保在遇到异常时能够自动进行重试操作,并有效管理事务,保证数据一致性。
摘要由CSDN通过智能技术生成