如何从aspectj中排除方法 [英] How to exclude methods from aspectj

查看:46
本文介绍了如何从aspectj中排除方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to exclude several methods from log files using aspectj (Im usong spring and Load-time weaving). Is there a way to list the excluded methods in the aop.xml? I know i can do this for full classes but I'm looking for specific methods. or can i make a list in the aspect class? Thanks

推荐答案

我不知道如何在 XML 中执行此操作,但在方面本身中执行此操作很容易,因为可以使用布尔运算符组合切入点.

I don't know how to do it in an XML, but it's easy enough to do it in the aspects themselves, as pointcuts can be combined using boolean operators.

传统的aspectj语法:

Traditional aspectj syntax:

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

@AspectJ 语法:

@AspectJ syntax:

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

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

These are of course just samples. whatIDontWantToMatch() could also be composed of several pointcuts etc.

这篇关于如何从aspectj中排除方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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