2017-02-12 54 views
0

我想學習AspectJ,到目前爲止我已經習慣了很好的概念。所以在這裏我試圖編寫一個對象的方面類進行驗證。但下面的代碼給我adviceDidNotMatch的事情。爲什麼下面的代碼給我「adviceDidNotMatch」

before(com.message.pojo.Entity entity) : call(*public com.message.helper.Processor.process(com.message.pojo.Entity)) 
    && args(entity) 
     && target(com.message.helper.MessageProcessor){ 
     ValidationUtil validation = new ValidationUtil(); 
     validation.validate(entity); 
    } 

現在我檢查的所有合格名稱都是正確的。請檢查我的Java項目結構的截圖。

[Project Structure

回答

0

您的切入點有點語法問題:與其call(* public應該call(public *,那麼它的工作原理。

順便說一下,您還可以通過以原生AspectJ語法導入來替換您的完全限定類名。只有基於註解的@AspectJ語法才需要FQDN。假設我們正在討論截圖中的ValidationAspect,對於同一包中的兩個類,您甚至不需要任何導入。試試像這樣:

package com.message.helper; 

import com.message.pojo.Entity; 

public aspect ValidationAspect { 
    before(Entity entity) : 
    call(public * Processor.process(Entity)) && 
    args(entity) && 
    target(MessageProcessor) 
    { 
    ValidationUtil validation = new ValidationUtil(); 
    validation.validate(entity); 
    } 
}