我正在使用 Spring AOP 拦截@MyAnnotation 注释的方法。拦截没问题。但是,不幸的是,我还没有到达我的注释实例。
我的注释:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface MyAnnotation {
String[] description();
}
我的配置方面
@Aspect
public class OAuthAspect {
@Pointcut(value = "execution(public * *(..))")
public void anyPublicMethod() {
}
@Pointcut(value = "@annotation(annotation)", argNames = "annotation")
public void anyAnnotationMethod(MyAnnotation annotation) {
}
@Around(value = "anyPublicMethod() && anyAnnotationMethod(annotation)")
public Object authorization(ProceedingJoinPoint pjp, MyAnnotation annotation) throws Throwable {
//annotation is null
}
}
示例切入点:
@Service
public class ContextService {
@MyAnnotation(description = {"de1", "des2"})
public String getAll() {
}
}
我不明白为什么我无法检索注释的实例。
如果有人有想法?
pc : 已编辑
对我来说,
ContextService
类甚至没有编译,因为您的注释中有错别字:String[] descrition();
(注意缺少的“p”)实际上应该是String[] description();
,然后它编译,我也可以打印注释实例。