2017-02-12 29 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); 
    } 
}