Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
326 views
in Technique[技术] by (71.8m points)

java - Spring AOP: get access to argument names

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

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...