An Introduction to Spring AOP

AOP Module of Spring provides aspect-oriented programming features and has built in support for AOP (aspect-oriented programming). In AOP program logic is divided into different parts called concerns.
Consider an application having different modules e.g. Registration , Appointment , Operation etc. as shown below . These modules perform different functionality. Each module has a specific functionality to perform which represents its concern like Registration module performs registration of customers so registration is its concern. But there are some other functionalities (concerns) which are needed in multiple module. The concerns that cut across multiple modules are called cross-cutting concerns like logging , security, data transfer. So to manage these cross-cutting concerns aspect-oriented programing is used otherwise each module need to address these concerns .

In AOP we create aspects which implement cross-cutting functionality. These aspects are hooked into the different modules wherever needed without modifying the existing code base of these modules which is possible by AOP only. This is the biggest advantage of AOP that we can implement functionality on one or more modules without changing implementation of those Modules which is not possible otherwise.
Aspect is like triggers in database . In database we can define triggers which perform some functionality on executing some DML statements. Consider a trigger which is executed when some data is inserted into the database and before inserting data it changes characters to capitals. Here we don’t modify the actual insertion query to change characters to capitals but triggers do it for us.
We will discuss how AOP is implemented later but first we need to understand some concepts of AOP.

AOP Concepts