Spring AOP : Getting parameters of the pointcut annotation

标签 spring aop 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";
}

如果我的aspect有没有办法读取显示方法中注解SampleAnnotation的value参数?

感谢您的帮助, 埃里克

最佳答案

将建议签名更改为

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

您将可以访问注释中的值。

docs了解更多信息。

关于 Spring AOP : Getting parameters of the pointcut annotation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5282242/

相关文章:

java - 在处理抛出 Throwable 的方法时,我应该避免抛出 Throwable 吗?

java - 在编译时编织时类路径上是否需要 AspectJ?

java - 监控 Bean 的变化以构建增量?

java - 如何在 Spring-Cloud-Stream 中配置重新连接到 Kafka

java - Eclipse 看到库但无法导入它

web-services - 使用 Spring 和 Axis 运行 webservice : unrecognized method

java - 建议 spring mvc http 消息转换器

java - @事务性与否

java - 我应该使用什么设计模式?使用 Spring 框架

java - Spring-Boot 2+ 强制使用 CGLIB 代理,即使 proxyTargetClass = false