Spring AOP – @AfterThrowing Advice

Facebooktwitterredditpinterestlinkedinmailby feather

Spring AOP – @AfterThrowing Advice

As we have discussed in our previous tutorial, Advice is one of the essential concepts of the Spring AOP. The after throwing advice is one of the types of advices available in AOP. If a method exits by throwing an exception, the after throwing advice is executed.

Let’s understand the concept of after throwing advice with the help of an example.

Example of @AfterThrowing Advice

Here, we are going to create an example of after throwing advice using @AfterThrowing annotation.

Following are the steps to create an example of @AfterThowing:

  • Create the bean

In this step, we are going to create a bean named Account, that contains the object.

Account.java

  • Create a DAO class

In this step, we are going to create a DAO class named StudentAccountDao, that contains the business logic of the application.

StudentAccountDao.java

  • Create a class that performs component scanning

In this step, we are going to create a class named DemoAOP, that performs component scanning.

DemoAop.java

  • Create an aspect class for aspect logic

In this step, we are going to create a class named AspectClass, which contains the aspect logic (all advice types).

AspectClass.java

  • Create the main class

In this step, we are going to create a main class named App, that contains the main method.

App.java

Output

Example of @AfterThrowing Advice
Facebooktwitterredditpinterestlinkedinmailby feather