This content originally appeared on DEV Community and was authored by Pramuda Liyanage
What is a Concern?
The concern is behavior that we want to have in a particular module of an application. A concern may be defined as a functionality we want to implement.
What is Cross Cutting Concerns?
In any application, there is some generic functionality that is needed in many places. But this functionality is not related to the application's business logic. Suppose you perform a role-based security check before every business method in your application. Here security is a cross-cutting concern. It is required for any application but it is not necessary from the business point of view, it is a simple generic functionality we have to implement in many places in the application. The following are examples of the cross-cutting concerns for the enterprise application.
** Logging and tracing
** Transaction management
** Security
** Caching
** Error handling
** Performance monitoring
** Custom business rules
Spring Aspect Oriented Programming Overview
Most of the enterprise applications have some common crosscutting concerns that are applicable to different types of Objects and modules. Some of the common crosscutting concerns are logging, transaction management, data validation, etc.
In Object Oriented Programming, modularity of application is achieved by Classes whereas in Aspect Oriented Programming application modularity is achieved by Aspects and they are configured to cut across different classes.
Spring AOP takes out the direct dependency of crosscutting tasks from classes that we can't achieve through normal object oriented programming model. For example, we can have a separate class for logging but again the functional classes will have to call these methods to achieve logging across the application.
What IS AOP?
AOP is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns.
Before we dive into the implementation of Spring AOP implementation, we should understand the core concepts of AOP.
Aspect => An aspect is a modularization of a concern that cuts across multiple classes
Joinpoint => A Joinpoint is a point during the execution of a program, such as the execution of a method or the handling of an exception.
Pointcut => A Pointcut is a predicate that helps match an Advice to be applied by an Aspect at a particular JoinPoint.We often associate the Advice with a Pointcut expression, and it runs at any Joinpoint matched by the Pointcut.
Advice => An Advice is an action taken by an aspect at a particular Joinpoint. Different types of advice include "around," "before," and "after."In Spring, an Advice is modelled as an interceptor, maintaining a chain of interceptors around the Joinpoint.
Proxy => Proxy is the object which is created by the framework after applying the advice on the target object.
Target => Target is the application object on which the advice will be applied.
Sources : https://www.baeldung.com/spring-aop https://www.codejava.net/frameworks/spring/understanding-spring-aophttps://www.journaldev.com/2583/spring-aop-example-tutorial-aspect-advice-pointcut-joinpoint-annotations
Thank You….
This content originally appeared on DEV Community and was authored by Pramuda Liyanage
Pramuda Liyanage | Sciencx (2021-11-02T18:06:48+00:00) Cross Cutting Concerns in Spring Framework. Retrieved from https://www.scien.cx/2021/11/02/cross-cutting-concerns-in-spring-framework/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.