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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With