2017-08-16 83 views
0

我有一个切入点表达式来调用包中的所有方法。切入点表达式来获取参数和注释值

某些方法可能有注释和需要获得建议的参数。

我的东西试过这样

@Around("execution(* com.man.test..jmx..*(..)) && args(name,..) && @annotation(requiredJMX)") 

这种表达的问题是,如果有名称和注释参数存在,它将调用。

我可以调用包中的所有方法,同时name参数和annotation是可选的吗?

像这样的事情

@Around("execution(* com.man.test..jmx..*(..)) || args(name,..) || @annotation(requiredJMX)") 
+0

是不是你想要的第二个表达式? – dimitrisli

+0

我需要第二个表达式,但它没有工作 –

回答

1

如果你想获得注释和args的方法, 的价值你可以做这样的:

@Around("execution(* com.man.test..jmx..*(..)) public Object yourMethod(ProceedingJoinPoint joinpoint){

MethodSignature signature = (MethodSignature) joinPoint.getSignature(); 
Method method = signature.getMethod(); 
MyAnnotation annotation = method.getAnnotation(MyAnnotation.class); 
if(null != annotation && method.getParameters().length > 0 
    && "name".equals(method.getParameters()[0].getName())){ 

    //do your work 
} 

}

+0

“name”.equals(method.getParameters()[i] .getName()剂量匹配 –

+0

“name”是您的方法的第一个参数的名称.. –

+0

是的,这是行不通的,它返回args0 –