Spring AOP通过注释切入点注释无法检索

时间:2017-04-11 08:13:58

标签: spring-aop

我使用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:已编辑

1 个答案:

答案 0 :(得分:0)

对我而言,由于注释中存在拼写错误,因此课程ContextService甚至无法编译:{{1​​}}(请注意缺少的" p")应该是String[] descrition(); ,然后它编译,我也可以打印注释实例。

相关问题