Spring AOP Introduction


Spring AOP Introduction:

What exactly is Spring AOP? Aspect-Oriented Programming is possible in spring applications thanks to Spring AOP. Aspects in AOP enable the modularization of concerns that span many kinds and objects, such as transaction management, logging, and security (often termed crosscutting concerns).

Aspect-Oriented Programming (AOP) is a technique of thinking about programme structure that complements Object-Oriented Programming (OOP). The class is the primary unit of modularity in OOP, whereas the aspect is the primary unit of modularity in AOP. Aspects allow for the modularization of issues that span several kinds and objects, such as transaction management.
Spring AOP has the benefit of providing declarative enterprise services, which makes it a good alternative for EJB declarative services. Declarative transaction management is the most essential of these services. It enables users to build bespoke elements while combining OOP and AOP. Let's have a look at some AOP terms and concepts:

Aspect-Oriented Programming (AOP) in spring

Object-oriented programming allows developers to solve crosscutting problems in an application, such as authentication, transaction, security, and logging management. It divides the application logic into sections (known as Concerns). In spring AOP, there are five sorts of advice (Represents an action done by an aspect at a specific joinpoint).

  • It is indicated by the @Before annotation and performs a before joinpoint.
  • It is indicated by the @AfterReturning annotation and executes after the joinpoint has completed normally.
  • @AfterThrowing annotation represents this advice, which is executed if a method terminates by throwing an exception.
  • Around Advice: It is represented by @Around annotation and executes before and after a joinpoint.

Spring AOP supports four different types of devices: Before the method is executed, run the advise. After the method provides a result, run the advise method. Advice when a method throws an exception – Run after the method throws an exception.