微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java – Spring AOP:@annotation(注释)

我(当然)试图使用许多我不太了解的结构来维护项目.在试图弄清楚 Spring中的AOP使用的过程中,我遇到了带有以下注释的方法

@Around(value =“@ annotation(annotation)”)

所以@Around意味着我们在AOP中执行方法切入点的’around’版本,我明白了.我不知道其他部分是什么意思. Spring文档提供以下内容

@annotation – limits matching to join points where the subject of the
join point (method being executed in Spring AOP) has the given
annotation

我不知道这意味着什么 – “在Spring AOP中执行的方法”听起来像建议的方法,但我不知道我(或Spring)如何找出建议的方法.听起来它是具有“给定注释”的方法,但如果是这样,那么给出了什么注释?

这个注释建议了哪些方法?还有什么意思呢?

解决方法

如果您有以下Spring Bean:
@Component
public class foo {

    @com.pkg.Bar      
    void fooMe() {
    }
}

然后是以下建议:

@Around("@annotation(com.pkg.Bar)")

将围绕fooMe(或使用@Bar注释的任何其他Spring bean方法)调用拦截

@Transactional注释就是一个很好的例子

原文地址:https://www.jb51.cc/java/128022.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐