Search code examples
javaspringaop

is it possible to do 1 Advice to multiple PointCut?


For ex: i want to log every behavior in a book class. Is it possilbe to do it with Spring-AOP?

sample


Solution

  • you can try with bellow expression in @Around, for example :

        @Pointcut("execution(* AOPviaAnnotation.Book.*(..))")
        public void allMethodOfBook() {};
    
        @Around("allMethodOfBook()")
        public void logBookInfo(){
         ...
        }
    

    or try with ||

        @Pointcut("execution(* AOPviaAnnotation.Book.add(..))")
        public void addMethod() {};
        @Pointcut("execution(* AOPviaAnnotation.Book.delete(..))")
        public void deleteMethod() {};
    
        @Around("addMethod() || deleteMethod()")
        public void logBookInfo(){
         ...
        }