我們使用自定義註釋實現了「之前」的建議,以便只執行某些方法(如果對此問題不感興趣)業務邏輯適用。建議執行兩次之前......同一個連接點爲相同的方法列出兩次,所以它被調用兩次
我們看到每次調用方法都會調用兩次方面。
調試到它我看到Cglib2AopProxy$CglibMethodInvocation.proceed
有一個名爲:interceptorsAndDynamicMethodMatchers
的數組。這個數組列出了我們的PointCut ("RequiresX")
兩次。
這裏是連接點:
@Before(@annotation(requiresX)」)
public Object process(ProceedingJoinPoint joinPoint, RequiresACL requiresX) throws Throwable
{
Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
log.info(" method:" + method.getName());
// do business logic of the aspect…
log.info(" joinPoint.proceed with call to " + method.getName());
}
,這裏是我們的定製標註
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.Method)
public @interface RequiresX {
}
這裏是我們所能方法攔截:
@RequiresX()
public String someMethod() {
....
}
這似乎相當香草,但顯然我做錯了什麼。任何有關如何只執行一次通話建議的建議將不勝感激。