Search code examples
spring-aop

What is the default spring AOP aspect for all methods all packages and functions?


Help me with below spring aop expression , not sure what is wrong here

@Before("execution( (..)") is not working


Solution

  • From the question topic the requirement here is to advice the execution of all the public methods of beans across the application. Following pointcut expression would achieve the same.

    execution(public * *(..))
    

    Please be aware that the above expressoin is for sure to have undesired results. This is because the scope of this expression is for all the spring application context managed beans , which includes the framework beans as well.

    A better approach would be to target only the beans from your application , an example would be

     execution(* com.xyz.service..*.*(..)) 
    

    This pointcut targets execution of any method defined in the service package or one of its sub-packages

    Both examples are taken from the Spring reference documentation - AOP pointcut examples

    Recommended reading.