Master java skills

Spring AOP

AOP stands for Aspect Oriented Programming. There are certain concepts that constitute AOP. Let’s understand them first.

Concern

A concern is a certain behaviour that we want to implement in a module of an application. Since, in java, behaviour is implemented using a method, we can understand that concerns can be implemented using methods in AOP.

For example – printing a certain statement can be a concern (such as in log files). Or a certain program logic can also be a concern.

Cross-cutting Concern

A cross-cutting concern is the one that is applicable at many places in your program. For example, you want to print one statement as the first statement in all your methods of your application, so, that one statement would be called a cross-cutting concern.

AOP

Aspect oriented programming is a technique that focuses upon breaking down a program logic into modules by separating cross-cutting concerns. These cross-cutting concerns can be formed into a unit called Aspect. This is typically a java class.

Aspect

An aspect is a modularization of a concern that cuts across multiple classes. So, a behaviour that is applicable at many places in various classes can be encapsulated into a class known as Aspect.

Advice

An advice is a method that is executed when a certain condition is met. These certain points which have a condition are known as join points. There are various types of advice as follows

  1. Before Advice – This executed before a join point is met.
  2. After Advice – This is further categorized into 3 types
  • After Returning Advice – This executes after returning successfully from a join point (method).
  • After Throwing Advice – This executes after throwing an exception from a join point (method).
  • After (finally) Advice – This advice always executes regardless of that fact whether exception is thrown or not.

3. Around Advice – This adive executes before and after the join point.

Join Point

It is an expression on which an advice executes.

Point Cut

It is a set of join points that matches a certain expression.

Introduction

Introduction means introduction of additional method and fields for a type. It allows you to introduce new interface to any advised object.

Target Object

It is the object i.e. being advised by one or more aspects. It is also known as proxied object in spring because Spring AOP is implemented using runtime proxies.