我有一个方面可以根据目标方法的详细信息进行各种计算,因此会提前提取这些内容,如下所示:
@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}。有人会知道我可能缺少什么,或者这是一个错误?
这是我正在反对的目标方法的签名:
Long createAccount(RequestAccountDetails accountDetails);
答案 0 :(得分:1)
适合我:
@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的签名更改为:
public Object validateParams(ProceedingJoinPoint joinPoint) throws Throwable
因为createAccount()
返回Long。否则我收到错误:applying to join point that doesnt return void: {0}