必须设置属性'表达'在尝试匹配之前

时间:2016-01-05 15:29:01

标签: spring aop spring-aspects

当我试图解决这个SO question ...

我面对

Must set property 'expression' before attempting to match

1 个答案:

答案 0 :(得分:1)

问题是,我对@AfterThrowing注释中的切入点没有价值:

<强>错

@AfterThrowing(throwing = "ex")
public void intercept(DataAccessException ex) throws Exception {
    //throw DatabaseException
    System.out.println("DAE");
    throw new IllegalArgumentException("DAE");
}

@AfterThrowing(throwing = "ex")
public void intercept(RuntimeException ex) throws Exception {
    //throw ServiceException
    System.out.println("RE - " + ex.getClass());
    throw new IllegalArgumentException("RE");
}

<强>正确

@AfterThrowing(pointcut = "execution(public * *(..))", throwing = "ex")
public void intercept(DataAccessException ex) throws Exception {
    //throw DatabaseException
    System.out.println("DAE");
    throw new IllegalArgumentException("DAE");
}

@AfterThrowing(pointcut = "execution(public * *(..))", throwing = "ex")
public void intercept(RuntimeException ex) throws Exception {
    //throw ServiceException
    System.out.println("RE - " + ex.getClass());
    throw new IllegalArgumentException("RE");
}

我发现的类似问题是AspectJExpressionPointcut uses wrong classLoader,但我没有处理类加载器问题......