2012-11-01 25 views
2

我想將切入點應用於子類中的已實現方法,但AspectMethod未在此切入點周圍調用。 以下是我的配置和代碼:切入點不適用於抽象方法

public abstract class ParentClass { 
    protected abstract void buildResponse(QueryResponse qryResp,ContentSearchServiceResponseImpl cssResp); 
} 


public class ChildClass extends ParentClass { 
@override  
public void buildResponse(QueryResponse qryResp,ContentSearchServiceResponseImpl ssResp){ 
//doSomething 
} 

切入點:

<aop:pointcut id="pointcutId" 
      expression="execution(public * ParentClass.buildResponse(..))" /> 

OR

<aop:pointcut id="pointcutId" 
      expression="execution(protected * ParentClass.buildResponse(..))" /> 

OR

<aop:pointcut id="pointcutId" 
      expression="execution(public * ParentClass+.buildResponse(..))" /> 

對於任何切入點的上述方面的配置中的是不是created.I幾乎試過everything.If任何人有這方面的一些想法......我不能因爲我的情況下,多個子類直接使用子類的名稱都執行這一抽象方法

回答

4

嘗試

execution(public * buildResponse(..)) && within(ParentClass+) 

execution(public * buildResponse(..)) && target(ParentClass+) 

也請記住,一個類內部的內部電話(一個方法調用同一個類的另一種方法)不受任何建議,如果您使用的是「標準」春基於代理的AOP 。

+0

非常感謝。最後三行是主要的問題解決者。我的電話是內部電話,我希望能夠將切入點應用於他們。那麼是否有其他方法來涵蓋這些方法? –

+1

是的,使用縱向加載時間編織或編譯時編織。閱讀文檔[here](http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/aop.html#aop-aj-ltw)。 – pap