我使用的是Spring 4.3.是否可以获取传递给它的方法参数名称和值?我相信这可以使用AOP(建议之前)完成,如果可能的话,请给我一个源代码.
从以下上一个问题(AspectJ - 无法识别连接点表达式中的注释的存在),
我的目标:在一个方面,我希望能够从匹配函数中提取/检索所有带注释的参数,无论有多少.(然后应用一些处理,但这不是这个问题的范围)
所以目前,这就是我所做的(不工作):
@Before("execution (* org.xx.xx.xx..*.*(@org.xx.xx.xx.xx.xx.Standardized (*),..))")
public void standardize(JoinPoint jp) throws Throwable {
Object[] myArgs = jp.getArgs();
getLogger().info("Here: arg length=" + myArgs.length);
// Roll on join point arguments
for (Object myParam : myArgs) {
getLogger().info(
"In argument with " + myParam.getClass().getAnnotations().length
+ " declaread annotations");
getLogger().info("Class name is " + myParam.getClass().getName());
// Get only the one matching the expected @Standardized annotation
if (myParam.getClass().getAnnotation(Standardized.class) != null) {
getLogger().info("Found parameter annotated with @Standardized");
standardizeData(myParam.getClass().getAnnotation(Standardized.class), myParam);
}
} …Run Code Online (Sandbox Code Playgroud)