Spring AOP by annotation pointcut annotation not retrieve

问题描述 投票:0回答:1

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

spring spring-aop
1个回答
0
投票

对我来说,

ContextService
类甚至没有编译,因为您的注释中有错别字:
String[] descrition();
(注意缺少的“p”)实际上应该是
String[] description();
,然后它编译,我也可以打印注释实例。

© www.soinside.com 2019 - 2024. All rights reserved.