我有注释:
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface Retry {
int DEFAULT_RETRIES = 2;
int times() default DEFAULT_RETRIES;
}
它可以在类级别使用:
@Retry(times = 5)
public class PersonServiceClass {
//...
public void deletePerson(long id) {
//...
}
}
或方法级别(另一个类,不是 PersonServiceClass):
@Retry
public void deletePerson(long id) {
//...
}
这个方面被这样的类捕获:
@Aspect
@Component
public class RetryInterceptor {
@Around("@within(retry) || @annotation(retry)")
public Object around(ProceedingJoinPoint proceedingJoinPoint, Retry retry) throws Throwable {
System.out.println("around - " + retry);
System.out.println("joinpoint - " + proceedingJoinPoint);
return aroundHandler(proceedingJoinPoint, retry);
}
并且方面在方法或类级别上被正确捕获,但绑定有问题Retry
注解。
When @Around
如下:@Around("@within(retry) || @annotation(retry)")
then:
- 当在方法级别捕获时
retry
is binded
- 当在班级水平上被抓住时
retry
is null.
When @Around
如下@Around("@annotation(retry) || @within(retry)")
then:
- 当在方法级别捕获时
retry
is null.
- 当在班级水平上被抓住时
retry
is binded.
Spring Boot 父版本 - 2.1.1.RELEASE