ARTICLE DETAIL

建站实战干货

来自一线的建站与推广经验沉淀,每一条都经过真实交付验证。

aop使用自定义注解报错 cannot resolve symbol

2026/8/19 1:10:18 拓冰建站 浏览量
aop使用自定义注解报错 cannot resolve symbol

aop使用自定义注解报错 cannot resolve symbol '*',自定义一个注解 AuthTest,在aop场景下使用:@annotation(AuthTest)结果自定义注解报红。

错误写法:

    @Before("execution(* com.zhh.demo.controller.*.*(..)) && @annotation(AuthTest)")public void interceptor(JoinPoint point) {System.out.println("前置通知。。。");}

正确写法:

    @Before("execution(* com.zhh.demo.controller.*.*(..)) && @annotation(com.zhh.demo.common.annotation.AuthTest)")public void interceptor(JoinPoint point) {System.out.println("前置通知。。。");}

原因:如果自定义注解和aop类在同一个包下,@annotation中就可以只写注解名称,否则注解里面需要写全路径,例如:@annotation("注解全路径")。