Spring AOP – @AfterReturning Advice

Facebooktwitterredditpinterestlinkedinmailby feather

Spring AOP – @AfterReturning Advice

We have discussed earlier the types of advices available in Spring AOP. One of them is After Returning advice. It is an advice that executes after the normal execution of a method (without any exception).

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

Example of @AfterReturning Advice

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

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

  • Create a bean

In this step, we are going to create a bean named Account, that stores an object. We have also defined two constructors: no-argument and parametrized constructor to the Account class.

Account.java

  • Create the DAO class

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

StudentAccountDao.java

  • Create a class that performs component scanning

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

DemoAOP.java

  • Create a class that contains the Aspect logic

In this step, we are going to create a class named AspectClass, that contains the Aspect logic (advice types and pointcut expressions).

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

Create a class that contains the Aspect logic

← PreviousNext →

Facebooktwitterredditpinterestlinkedinmailby feather