Spring AOP:@annotation(annotation) [英] Spring AOP: @annotation(annotation)

查看:40
本文介绍了Spring AOP:@annotation(annotation)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am (of course) trying to maintain a project using many constructs I don't know that well. In the course of attempting to figure out the AOP use within Spring, I came across methods with the following annotation:

@Around(value = "@annotation(annotation)")

@Around(value = "@annotation(annotation)")

所以@Around 意味着我们正在 AOP 中执行方法切入点的around"版本,我理解这一点.我不知道另一部分是什么意思.Spring 文档提供了以下内容:

So @Around means we're doing the 'around' version of the method pointcut in AOP, I understand that. I don't know what the other part means. The Spring documentation gives the following:

@annotation - 限制匹配到连接点的主题连接点(在 Spring AOP 中执行的方法)具有给定的注释

@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)如何确定建议的方法.听起来像是具有给定注释"的方法,但如果是这样,则给出了什么注释?

I don't know what that means - "method being executed in Spring AOP" sounds like the advised method, but I don't know how I (or Spring) figure out which methods are being advised. It sounds like it is the methods that have "the given annotation", but if so, what annotation has been given?

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

What methods are advised by this annotation? And what else does it mean?

推荐答案

如果你有以下 Spring Bean:

if you have the following Spring Bean:

@Component
public class foo {

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

那么下面的忠告:

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

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

Will invoke the interceptor around fooMe (or any other Spring bean method annotated with @Bar)

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

The @Transactional annotation is a good example

这篇关于Spring AOP:@annotation(annotation)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆