当我试图解决这个SO 问题时......
我面对
Must set property 'expression' before attempting to match
问题是,我在@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 使用了错误的 classLoader,但我没有处理类加载器问题......