Aspectj aspect for specifying multiple packages

I wanted to specify a template for aspectj @ Acoustic aspect, which includes several packages.

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

The template 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 template does not work. Although the indication of one template without && working conditions.

Can anyone suggest what is wrong with this template?

Thank you
Gayatri

+5
source share
1 answer

&&stands for logical AND. Here you need a boolean ORwhich in AspectJ is equal ||.

@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 is the equivalent inline expression:

@Pointcut("execution(* aaa.bbb.ccc.ddd.*.*(..)) || execution(* aaa.bbb.ccc.eee.*.*(..))")
public void methodInDddOrEeePackageInline() {}

See the Spring AOP documentation for more details .

+15
source

All Articles