I have an aspect that does various computations based on the target method's details, and therefore extracts these upfront as follows:
@Around("execution(* com.xyz.service.AccountService.*(..))")
public void validateParams(ProceedingJoinPoint joinPoint) throws Throwable {
final MethodSignature signature = (MethodSignature) joinPoint.getSignature();
final String methodName = signature.getName();
final String[] parameterNames = signature.getParameterNames();
final Object[] arguments = joinPoint.getArgs();
...
...
...
joinPoint.proceed();
}
Of the extracted details, all reflect the expected info except parameterNames which always returns null. I would expect it to return {accountDetails} as per the signature below. Would anyone know what I may be missing, or is this a bug?
Here's the signature of the target method I am working against:
Long createAccount(RequestAccountDetails accountDetails);
works for me:
@Aspect
public class MyAspect {
@Around("execution(* *(..)) && !within(MyAspect)")
public Object validateParams(ProceedingJoinPoint joinPoint) throws Throwable {
final MethodSignature signature = (MethodSignature) joinPoint.getSignature();
final String[] parameterNames = signature.getParameterNames();
for (String string : parameterNames) {
System.out.println("paramName: " + string);
}
return joinPoint.proceed();
}
}
output: paramName: accountDetails
I have changed the signature of validateParams to:
public Object validateParams(ProceedingJoinPoint joinPoint) throws Throwable
because createAccount()
returns a Long. Otherwise I get the error: applying to join point that doesnt return void: {0}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With