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

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

问题描述:

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

Consider I have defined the following aspect:

@Aspect
public class SampleAspect {

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

和注释

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

是否可以通过显示方法读取显示方法中的注释SampleAnnotation的value参数?

Is there a way to read the value parameter of the annotation SampleAnnotation in the display method if my aspect?

感谢您的帮助, 埃里克

Thanks for your help, erik

将建议签名更改为

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

,您将可以访问批注中的值.

and you will have access to the value in the annotation.

请参见

See docs for more info.