【发布时间】:2020-09-17 07:11:22
【问题描述】:
我已阅读以下有价值的链接:
- Spring AOP pointcut for annotated argument
- How to write an Aspect pointcut based on an annotated parameter
- AspectJ pointcut expression match parameter annotations at any position
考虑这个对setter方法的请求
public void setSomething(@ParameterLevel(name="abc") String something){
this.something = something;
}
我有以下并且工作正常:
@Pointcut("execution(* *.*(@somepackage.ParameterLevel (*)))")
void parameterLevel01() {}
现在我想通过如下方法的参数检索@ParameterLevel 注释:
@Pointcut("execution(* *.*(@somepackage.ParameterLevel (*)))")
void parameterLevel01(ParameterLevel parameterLevel) {} <--To be used directly in the advice method
目的是直接使用Annotation如何在advice方法中作为参数
类似的东西,例如:
@within(classLevel) 为@ClassLevel 在:
@ClassLevel
public class SomeClass {
...
}
@annotation(methodLevel) 为@MethodLevel 输入:
@MethodLevel
public void somethingToDo(){
...
}
如何实现这一目标。有可能吗?我正在使用 AspectJ 1.9.6
【问题讨论】:
-
我不明白你为什么在这里问这个问题。您阅读了其他已重复的问题,我想您也阅读了我接受的两个答案。您是否真的认为,如果可以像您希望的那样将参数注释绑定到建议方法参数的简单方法是可能的,我会发布更复杂的方法吗?
-
此外,在签名中使用
.., something, ..意味着something可以出现多次,因此将其绑定到单个值参数将是不明确的。您可以想象将其绑定到一个数组,但在今天(AspectJ 1.9.6)这是不可能的。所以请使用我的解决方案。谢谢。 -
.., something, ..已更新为被删除。现在即将只有一个参数。此外,在我的帖子末尾说How accomplish this goal. Is possible?我可以假设对于 AspectJ 的新版本添加了支持或功能。 -
You read the other questions of which this is a duplicate already and I guess you also read my two accepted answers我的问题不是重复的,因为帖子中没有请求直接在通知方法中检索参数的注释,它只是将切入点应用于方法带有注释的参数。不一样 -
就像我说的,答案就在您已经找到的其他问题中。我在这里的回答有点多余,只是已经存在的一种变体。这只是对你的礼貌。你很幸运,我不得不在机场消磨时间,等待转机。 ??????
标签: java annotations aop aspectj