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("==================&