定义了4个注解,@ApiCheck注解中组合了@CheckOne,@CheckTwo,@CheckThree三个注解,三个注解都写了aspect切面环绕方法,现在在Controller类方法上标@ApiCheck注解,想要自动去调用执行@CheckOne,@CheckTwo,@CheckThree的切面环绕方法。但切入点始终无法匹配,请问如何修正?
@ApiCheck
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@CheckOne
@CheckTwo
@CheckThree
public @interface ApiCheck {
}
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface CheckOne {
}
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface CheckTwo {
}
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface CheckThree {
}
ApiCheckAspect切面类切入点
@Around("execution(* com.xx.api.controller..*.*(..)) " +
"&& @annotation(com.xx.api.annotation.ApiCheck) " +
"&& (@annotation(org.springframework.web.bind.annotation.RequestMapping) " +
"|| @annotation(org.springframework.web.bind.annotation.GetMapping) " +
"|| @annotation(org.springframework.web.bind.annotation.PostMapping) " +
"|| @annotation(org.springframework.web.bind.annotation.DeleteMapping) " +
"|| @annotation(org.springframework.web.bind.annotation.PatchMapping)" +
")"
)
CheckOneAspect切入点(Two和Three类似)
@Pointcut("( target(com.xx.api.annotation.ApiCheck) && " +
"@annotation(com.xx.api.annotation.CheckOne) " +
") || " +
"(execution(* com.xx.api.controller..*.*(..)) && " +
"@annotation(com.xx.api.annotation.CheckOne) && (" +
"@annotation(org.springframework.web.bind.annotation.RequestMapping) || " +
"@annotation(org.springframework.web.bind.annotation.GetMapping) || " +
"@annotation(org.springframework.web.bind.annotation.PostMapping) || " +
"@annotation(org.springframework.web.bind.annotation.DeleteMapping) || " +
"@annotation(org.springframework.web.bind.annotation.PatchMapping) " +
"))")
private void aspectPointcut(){}
执行结果是 ApiCheckAspect 切入点进去了,但 CheckOne 的没有执行进去。请问这一句 target(com.xx.api.annotation.ApiCheck) && @annotation(com.xx.api.annotation.CheckOne) 指向 ApiCheck 组合注解同时注解上存在 CheckOne 注解的方式是怎么错的,并求正解解法。谢谢!