AspectJ JoinPoint question

牧云@^-^@ 提交于 2019-11-30 19:03:48

This should work:

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

The parameterNames should match what you have passed in.

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 pointcut

public pointcut pointcutName():
        execution(* ClassName.method(..));

Getting Parameter names of the method

before():pointcutName(){
String[] paramNames = ((CodeSignature) thisJoinPointStaticPart
                .getSignature()).getParameterNames();
 for(String paramName:paramNames){
            System.out.println(paramName);
        }
}

Getting Parameter Values:

before():pointcutName(){
Object[] paramValues = thisJoinPoint.getArgs();

for (Object object:paramValues){
        System.out.println(object.toString);
        }
}

Getting Method Return Value:

after() returning(Object objectReturn) :pointcutName(){
    System.out.println(objectReturn);
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!