简体   繁体   中英

Matching pointcuts with specific arguments

In Spring, I want an expression that matches a method with specific arguments.

Right now I have this expression

     execution(* delete(..))

But I want to match specific arguments since there are 4 delete methods in the particular class I am interested in.

I want something like this

       execution(* delete(com.xyz.A, com.xyz.B,java.lang.String )

This is what I wrote and is not working. Am I missing something ?

The syntax looks correct. I believe you are missing a closing parenthesis.

@Pointcut("execution(* delete(com.xyz.A, com.xyz.B,java.lang.String))")

The reason that it is probably not so obvious is that it is a part of the String of your Pointcut annotation (assuming you are using the annotation based approach), and so if your IDE of choice does not validate Pointcut annotations, it won't throw a big red squiggly in your face.

I do it the following way:

@Pointcut("target(com.xyz.ClassName) && execution(* myMethod(com.xyz.A, com.xyz.B,java.lang.String))")

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM