AspectJ AJ文件与@Aspect注释的Java类等效

时间:2018-10-19 09:21:22

标签: java aspectj aspect

我是Aspectj的新手。我正在尝试将.aj文件转换为Java @Aspect注释的类。

我的问题:这与.aj实现等效吗?

这是工作的.aj文件:

public aspect AspectException
{
    public pointcut scope(): within(com.example..*) && !within(com.example.test.Constants) && !within(com.example.test.update.UpdateAction);

    before(Exception e): handler(Exception+) && args(e) && scope()
    {
        logException(e, thisJoinPointStaticPart, thisEnclosingJoinPointStaticPart);
    }

    protected void logException(Exception e, StaticPart location, StaticPart enclosing)
    {
  }
}

和我的Java注释类: @Aspect

public class AspectExceptionAspect {

    @Pointcut("within(com.example..*) &&" +
            "!within(com.example.test.Constants) &&" +
            "!within(com.example.test.update.UpdateAction)")
    public void scope() {}

    @Before(value = "com.AspectExceptionAspect.scope() && "
            + "handler(Exception+) &&"
            + "args(e)")
    public void beforeScope(Exception e, JoinPoint.StaticPart joinPointStaticPart, JoinPoint.EnclosingStaticPart joinPointEnclosingStaticPart) {
        logException(e, joinPointStaticPart, joinPointEnclosingStaticPart);
    }
}

0 个答案:

没有答案