指定注解为:HeaderParam
处理过程:
@Around("execution(execution(* com.test.service.*.*(..))")
public Object exceptionHandle(ProceedingJoinPoint js){
try {
baseParamSetIp(js);
return js.proceed();
} catch (Throwable e) {
}
}
private void baseParamSetIp(ProceedingJoinPoint js){
MethodSignature methodSignature = (MethodSignature) js.getSignature();
Annotation[][] annotations = methodSignature.getMethod().getParameterAnnotations();
Object[] objects = js.getArgs();
int index=0;
boolean headerParamFlag = Boolean.FALSE;
LOOP:
for(int i = 0; i < annotations.length; i++){
for(Annotation a: annotations[i]){
if(a.annotationType() == HeaderParam.class){
index = i;
headerParamFlag = Boolean.TRUE;
break LOOP;
}
}
}
if(headerParamFlag){
Object obj = objects[index];
System.out.println(obj);
}
}
spring aop获取方法指定annotation的参数
最新推荐文章于 2024-05-14 17:37:13 发布