October 2017
Intermediate to advanced
396 pages
10h 2m
English
Let's see the use of the @AfterThrowing annotation:
//After failed transfer service
@AfterThrowing("execution(* com.packt.patterninspring.chapter6. bankapp.service.TransferService.transfer(..))")
public void rollback() {
System.out.println("bank rolled back your transferred amount");
}
You can also use the @AfterThrowing annotation with the throwing attribute, it only invokes advice if the right exception type is thrown:
//After failed transfer service
@AfterThrowing(value = "execution(* com.packt.patterninspring.chapter6. bankapp.service.TransferService.transfer(..))", throwing="e"))
public void rollback(DataAccessException e) {
System.out.println("bank rolled back your transferred amount");
}
Execute every ...
Read now
Unlock full access