Skip to content
Advertisement

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

Assuming my current package structure in a spring projects as :

com.stackoverflow
|- service
|- entities
|- controllers
   |- package1
   |- package2
|-util

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?

Advertisement

Answer

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

@Pointcut ("execution (* com.stackoverflow..*.*(..)) && " +
           "!execution (* com.stackoverflow.util..*.*(..))")
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement