Is there an AspectJ pointcut expression that searches for all subpackages?

So, I have an aspect with a declared method with the following expression:

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

This works fine for all classes in the aaa.bbb.ccc package. Now, however, I would like to grab all the classes in aaa.bbb , including aaa.bbb.ccc . So I tried to back it up to:

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

This only captures classes from aaa.bbb , but ignores classes from aaa.bbb.ccc . Is there a way to get an expression to search all subpackages recursively?

+6
source share
1 answer

Got! Text change is surprisingly trivial.

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

... becomes ...

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

Just add an extra period between the package name and the qualifier, and you will go to the race.

One of the problems that I encountered after making the changes was that all Spring exploded and collapsed on me. This was due to the fact that the aspect itself was in the aaa.bbb . Therefore, if you do, be sure to use the !within clause to free your aspect of trying to process yourself.

+14
source

Source: https://habr.com/ru/post/981307/


All Articles