Skip to content

How can I apply aop on a whole package except one subpackage

Assuming my current package structure in a spring projects as :

|- service
|- entities
|- controllers
   |- package1
   |- package2

How can I apply an aspect to all the packages under com.stackoverflow except on the package util?

Applying it to everything, the execution expression would be “com.stackoverflow...(..)”

What should the execution expression be in this case I want to remove the util subpackage from the execution expression?


Use the AND && and NOT ! operators in your Pointcut expression as

@Pointcut ("execution (* com.stackoverflow..*.*(..)) && " +
           "!execution (* com.stackoverflow.util..*.*(..))")