Get method arguments using Spring AOP?

后端 未结 8 1973
陌清茗
陌清茗 2020-11-29 01:13

I am using Spring AOP and have below aspect:

@Aspect
public class LoggingAspect {

    @Before(\"execution(* com.mkyong.customer.bo.CustomerBo.addCustomer(..         


        
相关标签:
8条回答
  • 2020-11-29 02:05

    You have a few options:

    First, you can use the JoinPoint#getArgs() method which returns an Object[] containing all the arguments of the advised method. You might have to do some casting depending on what you want to do with them.

    Second, you can use the args pointcut expression like so:

    // use '..' in the args expression if you have zero or more parameters at that point
    @Before("execution(* com.mkyong.customer.bo.CustomerBo.addCustomer(..)) && args(yourString,..)")
    

    then your method can instead be defined as

    public void logBefore(JoinPoint joinPoint, String yourString) 
    
    0 讨论(0)
  • 2020-11-29 02:05

    If it's a single String argument, do: joinPoint.getArgs()[0];

    0 讨论(0)
提交回复
热议问题