Chapter 12. Using Aspect-oriented Programming

In this chapter, we will cover the following recipes:

  • Creating a Spring AOP aspect class
  • Measuring the execution time of methods using an around advice
  • Logging method arguments using a before advice
  • Logging methods' return values using an after-returning advice
  • Logging exceptions using an after-throwing advice
  • Using an after advice to clean up resources
  • Making a class implement an interface at runtime using an introduction
  • Setting the execution order of the aspects

Introduction

Aspect-oriented programming (AOP) is about inserting and executing, at runtime, extra pieces of code at various points of the normal execution flow of a program. In AOP terminology, these pieces of code are methods that are called advices ...

Get Spring Cookbook 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.