如何在aspectJ中排除getter和setter?

问题描述:

我的 Maven 项目中有一个 aspectJ 类,它帮助我显示项目中任何被调用方法的开始和结束.我现在尝试排除所有 getter 和 setter.我尝试修改此注释:@Around("execution(public * *(..))经过@Around("execution(public * *(..) && !within(* set*(..))")

I have a class aspectJ in my maven project whitch hepls me to show the Begin and the End of any called method in my project. I try now to exclude all getters and setters. I try modify this annotation: @Around("execution(public * *(..)) by @Around("execution(public * *(..) && !within(* set*(..))")

但它并没有变坏,它在控制台中给了我:

But it doesn't whork and it gives me that in the consol:

 [ERROR] Failed to execute goal org.codehaus.mojo:aspectj-maven-plugin:1.7:compile (default) on project spb-lceb: AJC compiler errors:
 [ERROR] error at @Around("execution(public * *(..) && !within(* set*(..))")
 Syntax error on token "execution(public * *(..) && !within(* set*(..))", ")" expected

任何想法

我认为这只是一个错字,因为您在 & 之前的执行调用结束时缺少一个 )& 运算符:

I think it's only a typo because you have a mising ) at the end of the execution call before the && operator:

@Around("execution(public * *(..) && !within(* set*(..))")

应该是:

@Around("execution(public * *(..)) && !within(* set*(..))")

试试吧,应该就可以了.

Try it, that should do the trick.

对于以 Get 开头的方法,最好的解决方案是重命名它们以消除这种冲突.

And for the methods that begins with Get the best solution is to rename them to get rid of this conflict.