After Aspect

Learn how to perform a task after an intercepted method call has been executed and what to do in case it throws an exception.

Logging is a cross-cutting concern for which aspects can be created. In this lesson, we will create another aspect that will log the values returned after the methods have been executed.

We will create an aspect called LoggingAspect by creating a Java class and mark it with @Aspect and @Configuration annotations.

@Aspect
@Configuration
public class LoggingAspect {

}

@AfterReturning annotation

The LoggingAspect class will have a method LogAfterExecution(), which will print a message if the method is successfully executed.

To tell spring-aop that this method needs to be called after the intercepted method call is executed, we will use the @AfterReturning annotation.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.