aop+定向发送三次请求

本文介绍了如何自定义注解并创建AOP切面,利用around通知进行异常处理。通过注解参数捕获并处理特定级别的异常,展示了AOP在控制异常逻辑中的应用。
摘要由CSDN通过智能技术生成

1.自定义一个注解

2.做一个切面,选择around

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Documented
public @interface Retry {
    /**
     *  重试次数 ,默认为1
     */
    int retryTimes() default 1;

    /**
     * 重试间隔 ms,默认1s
     */
    int interval() default 1000;

    /**
     *  需要重试的异常, 默认为Exception及其子类
     */
    Class[] needRetryException() default {};
}
@Slf4j
@Aspect
@Component
@EnableAspectJAutoProxy(proxyTargetClass = true)
public class RetryAspect {

    /**
     * 定义切点
     */
    @Pointcut("@annotation(com.tqmall.legend.annotation.Retry)")
    public void pointCut() {
    }


    @Around("pointCut()")
    public Object process(ProceedingJoinPoint joinPoint) {
        Object target = joinPoint.getTarget();
        log.info("==================&
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值