This problem has been solved partly before,The question I asked builds on the answer to this question reference: How to intercept meta annotations (annotated annotations) in Spring AOP
related codes above
package de.scrum_master.app;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
@Retention(RUNTIME)
@Target({ TYPE })
public @interface MetaAnnotation {}
package de.scrum_master.app;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
@Retention(RUNTIME)
@Target({ TYPE })
@MetaAnnotation
public @interface MyAnnotation {}
but only when the meta-annotation is added to the type,it works. Now I hope that when the annotation is used on the method, it can also be intercepted by asepct.
The following expression can intercept all MetaAnnotation used on type, but it cannot be applied to method
package de.scrum_master.aspect;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
@Aspect
public class MetaAnnotationInterceptor {
@Before(
"execution(* *(..)) && (" +
"within(@de.scrum_master.app.MetaAnnotation *) || " +
"within(@(@de.scrum_master.app.MetaAnnotation *) *)" +
")"
)
public void myAdvice(JoinPoint thisJoinPoint){
System.out.println(thisJoinPoint);
}
}
I tried
"annotation(@de.scrum_master.app.MetaAnnotation *) || " + "annotation(@(@de.scrum_master.app.MetaAnnotation *) *)" +
and
"@annotation(de.scrum_master.app.MetaAnnotation) || " + "@annotation(@annotation(de.scrum_master.app.MetaAnnotation))" +
And some similar combinations, but they will all report an error: the aspect expression cannot be parsed
I want to know what kind of expression can intercept meta annotations annotated on method