Reputation: 11
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?
Upvotes: 1
Views: 4629
Reputation: 4011
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.
Upvotes: 1