我有一个方面可以根据目标方法的详细信息进行各种计算,因此可以提前提取如下:
@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();
}
在提取的详细信息中,除了总是返回null的parameterNames之外,所有信息都反映了预期的信息。我希望它按照下面的签名返回{accountDetails}。有人知道我可能遗漏了什么吗,或者这是一个bug吗?
这是我所反对的目标方法的签名:
Long createAccount(RequestAccountDetails accountDetails);
适用于我:
@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();
}
}
输出:paramName: accountDetails
我已将validateParams的签名更改为:CCD_ 2,因为CCD_。否则我会得到错误:applying to join point that doesnt return void: {0}