How to write an Aspect pointcut based on an annotated parameter

后端 未结 2 555
萌比男神i
萌比男神i 2020-12-08 23:25

I\'m having a bit of trouble working out how to create a pointcut that will operate on beans that have a specific annotated parameter. My eventual aim is to validate the val

2条回答
  •  醉酒成梦
    2020-12-09 00:03

    This is what I ended up at after fiddling about with it (imports omitted):

    @Aspect
    public class VerifyAspect {
    
        @Before("execution(* *(.., @annotations.MyAnnotation (*), ..)) && args(.., verifyMe)")
        public void verifyInvestigationId(final Object verifyMe) {
            System.out.println("Aspect verifying: " + verifyMe);
        }
    }
    

    No need for anything Spring-specific, as AspectJ already provides you with the parameters if so desired.

提交回复
热议问题