AspectJ JoinPoint问题 [英] AspectJ JoinPoint question

查看:94
本文介绍了AspectJ JoinPoint问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在使用JoinPoint捕获运行时传递给服务方法的参数.尽管JoinPoint可以帮助我检索参数值,但我看到它没有提供任何好的API来检索参数名称,参数类型,当传递的参数是数组时的单个参数值等.

I am currently using JoinPoint to capture the parameters passed to service methods at runtime. Though JoinPoint helps me retrieve the parameter values, I see that it doesn't provide any good API to retrieve the names of the parameters, parameter types, individual parameter values when the parameter passed is an array etc.

这是一个例子:

public void doIt(String user, Attribute[] attr, Integer[] i, boolean bool, List<Attribute> list){.....}

对于上述方法,当我使用JoinPoint.getArgs()时,我看到参数的垃圾值是数组或集合.如果参数是数组或集合,如何验证它们是否是其中之一,以及如何遍历它们以检索单个值?

For the above method, when I use JoinPoint.getArgs(), i see a garbage value for the parameter which is an array or a collection. If the parameter is an array or a collection, how can I verify if they are one of those and how can I traverse them to retrieve individual values?

有什么建议吗? 谢谢

推荐答案

这应该有效:

MethodSignature signature = (MethodSignature)joinPoint.getSignature();
String[] parameterNames = signature.getParameterNames();
Object[] parameterValues = joinPoint.getArgs();

parameterNames应该匹配您传递的内容.

The parameterNames should match what you have passed in.

更新1:您可能正在关闭调试符号进行编译-(显式传递javac -g:none,或通过maven/ant中的标志传递).关闭调试符号后,名称将不可用,并且将由编译器替换为args1等.尝试使用未明确关闭调试符号的编译.

Update 1: You are probably compiling with debugging symbols turned off -(explicitly passing in javac -g:none, or through flags in maven/ant). With debugging symbols off, names will not be available and will replaced with args1 etc by the compiler. Try with a compilation with debug symbols not explicitly turned off.

这篇关于AspectJ JoinPoint问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆