本文介绍了Aspectj方面,用于指定多个包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为Aspectj @Around方面指定一个模式,其中包括多个包.
I wanted to specify a pattern for aspectj @Around aspect that includes multiple packages.
Example : package 1 : aaa.bbb.ccc.ddd
package 2 : aaa.bbb.ccc.eee
package 3 : aaa.bbb.ccc.eee.fff
我使用的模式:
@Around("execution(* aaa.bbb.ccc.ddd.*.*(..)) && execution(* aaa.bbb.ccc.eee..*.*(..))")
i.e Intercept packages aaa.bbb.ccc.ddd, aaa.bbb.ccc.eee and any sub-package of aaa.bbb.ccc.eee
但是这种模式似乎不起作用.尽管指定了一个不带&&的单一模式条件有效.
But this pattern doesnt seem to work. Though specifying a single pattern without && condition works.
有人可以建议这种模式有什么问题吗?
Can someone suggest whats wrong with this pattern?
谢谢,
盖亚特里
Thanks,
Gayathri
推荐答案
&&
表示逻辑AND
.这里需要的是逻辑OR
,在AspectJ中是||
.
&&
stands for logical AND
. What You need here is a logical OR
, that in AspectJ is ||
.
@Pointcut("execution(* aaa.bbb.ccc.ddd.*.*(..))")
public void methodInDddPackage() {}
@Pointcut("execution(* aaa.bbb.ccc.eee.*.*(..))")
public void methodInEeePackage() {}
@Pointcut("methodInDddPackage() || methodInEeePackage()")
public void methodInDddOrEeePackage() {}
以下等效的内联表达式:
Below equivalent inline expression:
@Pointcut("execution(* aaa.bbb.ccc.ddd.*.*(..)) || execution(* aaa.bbb.ccc.eee.*.*(..))")
public void methodInDddOrEeePackageInline() {}
请参见 Spring AOP文档页面以获取更多详细信息.
See this Spring AOP documentation page for more details.
这篇关于Aspectj方面,用于指定多个包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!