从下面的上一个问题(AspectJ - Presence of annotation in join point expression notrecognized),
我的目标:在一个方面,我希望能够从匹配函数中提取/检索所有带注释的参数,无论有多少。(然后应用一些处理,但这不是这个问题的范围)
所以目前,这就是我所做的(不工作):
@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);
}
}
}
这是建议匹配的代码:
public boolean insertLog(@Standardized(type = StandardizedData.CLIPON) CliponStat theStat) {
// ...
}
以及由 junit 测试生成的跟踪:
INFO: ICI: arg lenght=1
INFO: In argument with 0 declaread annotations
看起来它没有检测到注释
所以我的问题是:如何检测具有特定注释的参数?
有人知道怎么做吗?
在此先感谢您的帮助。
问候。
编辑:我发现这个线程Pointcut matching methods with annotated parameters,讨论同一件事,并应用了给定的解决方案,但它不起作用..