How can I exclude getters and setters in aspectJ?

情到浓时终转凉″ 提交于 2019-12-08 07:29:13

问题


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

Any idea


回答1:


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*(..))")

Should be:

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

Try it, that should do the trick.

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




回答2:


The accepted solution is clearly wrong because within(* set*(..)) will not even compile. This pointcut type needs a type signature, not a method signature. Furthermore, it only tries to take care of setters, not getters as asked by the OP.

The correct solution is:

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

By accepting the wrong solution the OP even irritated someone else trying is here. This is why after such a long time I am writing this answer.



来源:https://stackoverflow.com/questions/28297095/how-can-i-exclude-getters-and-setters-in-aspectj

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!