Search⌘ K
AI Features

After Aspect

Explore how to implement Spring AOP after advice to log returned values and exceptions from business methods. Understand the use of @AfterReturning, @AfterThrowing, and @After annotations to create modular logging and error handling aspects in your Spring applications.

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 in the io.datajek.springaop.movierecommenderaop.aspect package. Create a class named LoggingAspect and mark it with @Aspect and @Configuration annotations.

@Aspect
@Configuration
public class LoggingAspect {
private Logger logger = LoggerFactory.getLogger(this.getClass());
}
LoggingAspect class

@AfterReturning annotation

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