2017-04-18 107 views
0

我是AOP的新手,已經通過這裏的教程:https://eclipse.org/aspectj/並對方面的工作方式有基本的瞭解。使用AspectJ攔截方法調用並將其綁定到另一個方法

這就是我想要做的。

有一個稱爲「MyAnnotation」和@annotation可以說我有裝飾這樣

@MyAnnotation 
public void MyMethod() { 
    //something here 
} 

的方法我寫一個方面類是這樣的:

@Aspect 
public class MyAspect { 

@Around("@annotation(MyAnnotation)") 
public void MyAdvice(ProceedingJoinPoint p) throws Throwable { 
    // I want to call an intereceptor here, for example 
    SomeInterceptor.invoke(methodInvocation) 
    p.proceed(); 
} 
} 

SomeInterceptor處於依賴包,我不擁有代碼。它在org.aopalliance.intercept中擴展MethodInterceptor類。在調用MyMethod之前,我需要使用我的建議方法進行一些處理。我不能使用Guice.bindInterceptor並正在尋找一個類似的選擇。我不知道如何獲得我可以傳遞給方法的methodInvocation對象。

謝謝!

回答