java 用于指定多个包的 Aspectj 方面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7819300/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 21:33:36  来源:igfitidea点击:

Aspectj aspect for specifying multiple packages

javaspringaspectj

提问by crankparty

I wanted to specify a pattern for aspectj @Around aspect that includes multiple packages.

我想为包含多个包的 aspectj @Around aspect 指定一个模式。

Example : package 1 : aaa.bbb.ccc.ddd
          package 2 : aaa.bbb.ccc.eee 
          package 3 : aaa.bbb.ccc.eee.fff

Pattern which i used :

我使用的模式:

@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

谢谢,
加亚特里

回答by Roadrunner

&&stands for logical AND. What You need here is a logical OR, that in AspectJ is ||.

&&代表逻辑AND。您在这里需要的是一个逻辑OR,在 AspectJ 中是||.

@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() {}

See this Spring AOP documentationpage for more details.

有关更多详细信息,请参阅此Spring AOP 文档页面。