I would like to retrieve the parameters’s name of a method on MethodInterceptor class.
public Object invoke(MethodInvocation invocation) throws Throwable {
Method method = invocation.getMethod();
Class<?> declaringClass = method.getDeclaringClass();
Logger logger = LoggerFactory.getLogger(declaringClass);
//here some treatment
return invocation.proceed();
}
and i just can’t find how to retrieve with MethodInvocation instance the name of the method parameters. I’m not sure it’s possible..
You can not. Java does not keep the param names in runtime, therefore, the interceptors (or reflection api) do not have way to get that.
One way to solve this is to wrap your params in one class, and have field with names that correspond to your param names.