如何从aspectj中排除方法

 爆米花来爆料V 发布于 2023-02-07 15:39

我正在尝试使用aspectj从日志文件中排除几种方法(我只使用spring和Load-time编织).有没有办法列出aop.xml中的排除方法?我知道我可以为全班做这个,但我正在寻找具体的方法.或者我可以在方面类中列出一个列表?谢谢

1 个回答
  • 我不知道如何在XML中做到这一点,但是在方面本身很容易做到这一点,因为可以使用布尔运算符组合切入点.

    传统的aspectj语法:

    pointcut whatIDontWantToMatch() : within(SomeClass+) || execution(* @SomeAnnotation *.*(..));
    pointcut whatIWantToMatch()     : execution(* some.pattern.here.*(..));
    pointcut allIWantToMatch()      : whatIWantToMatch() && ! whatIDontWantToMatch();
    

    @AspectJ语法:

    @Pointcut("within(SomeClass+) || execution(* @SomeAnnotation *.*(..))")
    public void whatIDontWantToMatch(){}
    @Pointcut("execution(* some.pattern.here.*(..))")
    public void whatIWantToMatch(){}
    @Pointcut("whatIWantToMatch() && ! whatIDontWantToMatch()")
    public void allIWantToMatch(){}
    

    这些当然只是样品.whatIDontWantToMatch()也可以由几个切入点等组成.

    2023-02-07 15:42 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有