问题 Spring AOP:获取切入点注释的参数


考虑我已经定义了以下方面:

@Aspect
public class SampleAspect {

    @Around(value="@annotation(sample.SampleAnnotation)")
    public Object display(ProceedingJoinPoint joinPoint) throws Throwable {
        // ...
    }
}

和注释

public @interface SampleAnnotation {
    String value() default "defaultValue";
}

如果我的方面有没有办法在显示方法中读取注释SampleAnnotation的值参数?

谢谢你的帮助, 埃里克


12591
2018-03-12 11:36


起源

可能重复 在建议中访问注释值 - axtavt


答案:


将建议签名更改为

@Around(value="@annotation(sampleAnnotation)")
public Object display(ProceedingJoinPoint joinPoint, SampleAnnotation sampleAnnotation ) throws Throwable {
    // ...
}

并且您可以访问注释中的值。

看到 文档 了解更多信息。


13
2018-03-14 08:10



有关深入文档,请查看: docs.spring.io/spring/docs/3.0.3.RELEASE/...  - 第7.2.4.6节建议参数 - hoodieman