Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm using Spring 3.x, Java 6.

I have an @Around aspect with the following joinpoint:

@Around("execution(public * my.service.*.*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 and anotherArg

I understand that using:

CodeSignature signature = (CodeSignature)jointPoint.getSignature();
return signature.getParameterNames();

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.

Thanks L

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
306 views
Welcome To Ask or Share your Answers For Others

1 Answer

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).

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...