Spring AOP:访问参数名称 [英] Spring AOP: get access to argument names
问题描述
我正在使用Spring 3.x,Java 6.
I'm using Spring 3.x, Java 6.
我有一个带有以下连接点的@Around方面:
I have an @Around aspect with the following joinpoint:
@Around("execution(public * my.service.*.*Connector.*(..))")
所以,我基本上有兴趣拦截所有类公共方法的调用,类名以Connector结尾。到目前为止一直很好。
So, I'm basically interested in intercepting all calls to public methods of classes with the class name ending with "Connector". So far so good.
现在,在我的方面,我想访问方法的实际参数名称:
Now, in my aspect I would like to access the actual argument names of the methods:
public doStuff(String myarg, Long anotherArg)
myarg 和 anotherArg
我理解使用:
CodeSignature signature = (CodeSignature)jointPoint.getSignature();
return signature.getParameterNames();
实际上可以正常工作,但前提是我使用 -g flag(完全调试),我宁愿不这样做。
will actually work but only if I compile the code with the "-g" flag (full debug) and I would rather not do it.
是否有其他方法可以访问这种运行时信息。
Is there any other way to get access to that kind of runtime information.
谢谢
L
推荐答案
不幸的是你不能这样做: - (。这是众所周知的JVM /字节码限制 - 使用反射无法获取参数名称,因为它们并不总是存储在字节码中(与方法/类名相反)。
Unfortunately you can't do this :-(. It is a well known limitation of JVM/bytecode - argument names can't be obtained using reflection, as they are not always stored in bytecode (in the contrary to method/class names).
作为一种解决方法,几个框架/规范引入了对诸如 WebParam
( name
property)或 PathParam
。
As a workaround several frameworks/specification introduce custom annotations over arguments like WebParam
(name
property) or PathParam
.
目前你可以得到没有的东西符号是一组值。
For the time being all you can get without annotations is an array of values.
这篇关于Spring AOP:访问参数名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!