简体   繁体   中英

Spring AOP Error: error Type referred to is not an annotation type

I declared a annotation of Action

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Action {
    String name();
}

When I tried to make a Pointcut

@Aspect
@Component
public class LogAspect {
    @Pointcut("@annotation(com.wisely.highlight_spinrg4.ch1.aop.Action)") //it failed here
    public void annotationPointCut() {}

    @After("annotationPointCut()")
    public void after(JoinPoint joinPoint) {
        MethodSignature signature = (MethodSignature)
        joinPoint.getSignature();
        Method method = signature.getMethod();
        Action action = method.getAnnotation(Action.class);
        System.out.println("Annotation Interpreter " + action.name());      
    }

    @Before("execution(*com.wisely.highlight_spring4.ch1.aop.DemoMethodService.*(..))")
    public void before(JoinPoint joinPoint) {
        MethodSignature signature = (MethodSignature)
        joinPoint.getSignature();
        Method method = signature.getMethod();
        System.out.println("Method Interpreter" + method.getName());
    }
}

It threw an error: java.lang.IllegalArgumentException: error Type referred to is not an annotation type: com$wisely$highlight_spinrg4$ch1$aop$Action

I've no idea since I used @interface to set “Action” as annotation. Could anyone offer some help?

Try running a maven clean and install if you are using Maven. I suspect the Action annotation have the same name of a class or an interface inside one of your dependency and it's taking the wrong object for some reason.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM