Implementing AfterThrowing advice

The AfterThrowing advice will be executed when the matched methods of the target object exit with an exception. This is also useful when you want to take an action on an exception that occurred during execution of the method. Let's create AfterThrowing advice as follows:

    <aop:aspect id="sendMsg" ref="sendMsgAspect">      <aop:after-returning pointcut-ref="hrServiceMethods"           returning="retVal" method="sendMessageOnSuccessExit"/>      <aop:after-throwing pointcut-ref="hrServiceMethods"           method="sendMessageOnErrorExit"/>    </aop:aspect>

The sendMessageOnErrorExit advice method will be defined in the sendMessage aspect as follows:

//Advice method on existing of target method with some error / exceptionpublic void sendMessageOnErrorExit(JoinPoint ...

Get Java 9 Dependency Injection now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.