Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an AspectJ pointcut expression that searches all subpackages?

So I've got an aspect with a method declared with the following expression:

@Before("execution(* aaa.bbb.ccc.*.*(..))")

This works perfectly for all classes in the package aaa.bbb.ccc. Now, however, I would like to capture all classes in aaa.bbb, including those in aaa.bbb.ccc. So I tried backing it up to here:

@Before("execution(* aaa.bbb.*.*(..))")

This only grabs the classes from aaa.bbb, though, and ignores classes from aaa.bbb.ccc. Is there a way I can make the expression search for all subpackages recursively?

like image 381
asteri Avatar asked Jan 20 '15 19:01

asteri


1 Answers

Got it! The textual change is surprisingly trivial.

@Before("execution(* aaa.bbb.*.*(..))")

... becomes ...

@Before("execution(* aaa.bbb..*.*(..))")

Simply add the extra period between the package name and the qualifier, and you're off to the races.

One issue I encountered after making the change was that all of Spring blew up and crashed on me. That was because the aspect itself was in a subpackage of aaa.bbb. So if you do this, make sure you use a !within clause to exempt your aspect from trying to process itself.

like image 185
asteri Avatar answered Nov 15 '22 14:11

asteri