0

When I was trying to solve this SO question...

I faced

Must set property 'expression' before attempting to match
Community
  • 1
  • 1
Betlista
  • 10,327
  • 13
  • 69
  • 110

1 Answers1

1

Problem was, that I had no value for pointcut in @AfterThrowing annotation:

wrong

@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");
}

correct

@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");
}

Similar question I found was AspectJExpressionPointcut uses wrong classLoader, but I was not dealing with class loader problem...

Community
  • 1
  • 1
Betlista
  • 10,327
  • 13
  • 69
  • 110