用于截取带注释字段的切入点 [英] Pointcuts for intercept assignment of annotated fields

查看:89
本文介绍了用于截取带注释字段的切入点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个简单的审核框架,该框架使我可以审核用@Audit注释进行注释的类的字段.

I'm writing a simple auditing framework which allows me to audit the fields of a class which are annotated with an @Audit annotation.

可能的注释示例

class User {

    @Audit
    private String phoneNumber;

    private String name;

    @Audit
    public getName(){
        return name;
    };

    public setName(String name){
        this.name=name;
    }
}

到目前为止,我只能定义一个简单的切入点,该切入点监视以@Audit注释为注释的设置方法的调用:

So far I was only able to define a simple pointcut that watches calls to setters annotated with the @Audit annotation:

@Pointcut("call(* @Audit set*(*))")

一个切入点看起来如何监视上面示例中带注释的字段的分配?

How does a pointcut look that watches the assignment of fields that are annotated like in the above example?

推荐答案

不幸的是,它是

Spring AOP当前仅支持方法执行连接点 (建议在Spring bean上执行方法).场地 尽管支持现场,但并未实施拦截 可以在不破坏核心Spring AOP API的情况下添加拦截功能. 如果您需要建议现场访问和更新连接点,请考虑 语言,例如AspectJ.

Spring AOP currently supports only method execution join points (advising the execution of methods on Spring beans). Field interception is not implemented, although support for field interception could be added without breaking the core Spring AOP APIs. If you need to advise field access and update join points, consider a language such as AspectJ.

如果您要使用AspectJ,则可以使用 AspectJTM 5开发中有一些示例工具包开发人员的笔记本

If You were to use AspectJ, you can use set(FieldPattern) pointcut. There are some examples in The AspectJTM 5 Development Kit Developer's Notebook

set(@Audit * *)似乎可行,就set(* @Audit * . *)而言-我不确定,也许AspectJ将第一个通配符识别为字段修饰符,但是根据文档,第一个元素是注释,第二个是修饰符...

set(@Audit * *) seems to work, as for set(* @Audit * . *) - I'm not sure, perhaps AspectJ recognizes first wildcard as field modifiers but according to docs first element is annotation, second is modifier...

这篇关于用于截取带注释字段的切入点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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