[英]How can I exclude getters and setters in aspectJ?
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.我的Maven 项目中有一个aspectJ 类,它帮助我显示项目中任何被调用方法的开始和结束。 I try now to exclude all getters and setters.
我现在尝试排除所有 getter 和 setter。 I try modify this annotation:
@Around("execution(public * *(..))
by @Around("execution(public * *(..) && !within(* set*(..))")
我尝试修改此注释:
@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任何的想法
The accepted solution is clearly wrong because within(* set*(..))
will not even compile.接受的解决方案显然是错误的,因为
within(* set*(..))
甚至不会编译。 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.
此外,它只尝试处理 setter,而不是 OP 要求的 getter。
The correct solution is:正确的解决办法是:
@Around("execution(public * *(..)) && !execution(* set*(..)) && !execution(* get*(..))")
By accepting the wrong solution the OP even irritated someone else trying the same here .通过接受错误的解决方案,OP 甚至激怒了其他人在这里尝试相同的方法。 This is why after such a long time I am writing this answer.
这就是为什么在这么长时间后我写这个答案的原因。
I think it's only a typo because you have a mising )
at the end of the execution call before the &&
operator:我认为这只是一个错字,因为在
&&
运算符之前的执行调用结束时您有一个 mising )
:
@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.对于以Get开头的方法,最好的解决方案是重命名它们以摆脱这种冲突。
//package name to exclude
@Pointcut("execution(* com.aasif.dao.*.*(..))")
private void forDaoPackage() {}
//getter
@Pointcut("execution(* com.aasif.dao.*.get*(..))")
private void getter() {}
//setter
@Pointcut("execution(* com.aasif.dao.*.set*(..))")
private void setter() {}
//excluding getter and setter method
@Pointcut("forDaoPackage() && !(getter() || setter())")
private void forNoGetterSetter() {}
//applying to advice
@Before("forNoGetterSetter()")
public void excludingGetter() {
System.out.println("performCloud()");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.