SlideShare a Scribd company logo
Spring AOP 
Onkar Deshpande 
© Onkar Deshpande 
1
Agenda 
Understanding cross cutting concerns 
Need of AOP 
Aspect-oriented programming concepts 
AOP Terminologies 
Implementing aspect behavior 
AspectJ APIs and annotations 
Spring AOP application 
© Onkar Deshpande 
2
Functional Programming 
© Onkar Deshpande 
3
Object Oriented Programming 
© Onkar Deshpande 
4
Problem in OOP 
© Onkar Deshpande 
5
Object Oriented Solution 
© Onkar Deshpande 
6
Problem in solution provided by OOP 
An aspect is scattered or tangled as code 
Making it harder to understand and maintain 
To many relationship with cross-cutting concerns 
OOP creates a coupling between core and 
crosscutting concerns. This causes 
 Leads to duplicated code 
 Hard to maintain code 
 Hard to use code 
© Onkar Deshpande 
7
Better Solution 
Logging Transaction 
Aspect Configuration 
© Onkar Deshpande 
8
Advantages of this approach 
Increase the modularity 
By allowing separating cross-cutting concerns from 
business logic 
Making easy to understand and maintain 
Spring AOP will take care of calling concerns, we just 
need to declare about concerns once in configuration file 
 You can focus on the concerns at one place 
 Easier to add and remove concerns 
 Easier to modify or fine tune concerns 
 Easier to understand 
 Efficient to implement 
 More efficient 
© Onkar Deshpande 
9
What Is AOP 
Aspect-oriented programming, or AOP, is a 
programming technique that allows programmers to 
modularize crosscutting concerns 
It is often defined as a programming technique that 
promotes separation of crosscutting concerns with in a 
software system 
concerns : 
A concern is a particular issue, concept, or area of 
interest for an application: typically, a goal the 
application must meet 
© Onkar Deshpande 
10
Cross-cutting concerns 
The systems or concerns that tend to cut across multiple 
components in a system are referred as Cross-cutting concerns 
System wide concerns that span multiple modules. 
Cuts across the typical division of responsibility. 
Examples such as 
 Transaction Management 
 Security 
 Logging 
© Onkar Deshpande 
11
Cross Cutting Concerns in OOP Cont.. 
public class Account 
{ 
public void deposit() { 
// Transaction Management 
// Logging 
// Checking for the Privileged User 
// Actual Deposit Logic comes here 
} 
public void withdraw() { 
// Transaction Management 
// Logging 
// Checking for the Privileged User 
// Actual Withdraw Logic comes here 
} 
} 
AOP calls this kind of logic that cross-cuts the existing business logic as Cross-Cutting Concerns 
© Onkar Deshpande 
12
AOP vs OOP 
Object Oriented Aspect Oriented 
Class – code unit that encapsulates 
methods and attributes 
Aspect – code unit that encapsulates 
pointcuts, advice, and attributes 
Method signatures – define the entry 
points for the execution of method 
bodies 
Pointcut – define the set of entry 
points (triggers) in which advice is 
executed 
Method bodies – implementations of 
the primary concerns 
Advice – implementations of the cross 
cutting concerns 
Compiler – converts source code into 
object code 
Weaver – instruments code (source or 
object) with advice 
© Onkar Deshpande 
13
AOP Terminologies 
Terms Description 
Aspect A module which has a set of APIs providing cross-cutting 
requirements. For example, a logging module would be called 
AOP aspect for logging. An application can have any number of 
aspects depending on the requirement 
Join Point This represents a point in your application where you can plug-in 
AOP aspect. You can also say, it is the actual place in the 
application where an action will be taken using Spring AOP 
framework 
Advice This is the actual action to be taken either before or after the 
method execution. This is actual piece of code that is invoked 
during program execution by Spring AOP framework 
Pointcut This is a set of one or more join points where an advice should 
be executed. You can specify point cuts using expressions or 
patterns as we will see in our AOP examples 
© Onkar Deshpande 
14
AOP Terminologies 
Transaction 
Advice 
Method1 Method2 Method3 
Logging 
Advisor 
Join Point 
© Onkar Deshpande 
15
Types of Advice 
Advice Description 
before Run advice before the a method execution 
after Run advice after the a method execution regardless of its 
outcome 
after-returning 
Run advice after the a method execution only if method 
completes successfully 
after-throwing 
Run advice after the a method execution only if method 
exits by throwing an exception 
Around Run advice before and after the advised method is invoked 
© Onkar Deshpande 
16
Declaring an aspect 
A concern that cuts across multiple classses and 
layers 
import org.aspectj.lang.annotation.Aspect; 
@Aspect 
public class LoggingInterceptor 
{ 
// ... 
} 
© Onkar Deshpande 
17
Declaring a pointcut 
An expression mapped to a join point (method 
invocation) 
@Aspect 
Public class LoggingInterceptor 
{ 
@Pointcut( "execution( * pack.dao.*.*(..) )" ) 
private void daoLayer() 
{ 
// code 
} 
} 
© Onkar Deshpande 
18
Pointcut expression pattern 
The execution pointcut designator is used most often 
© Onkar Deshpande 
19
Pointcut expression examples 
Description Pointcut 
Any public method execution( public * *(..) ) 
Any public method defined 
in the dao package 
execution( public * pack.dao.*.*(..) 
) 
Any method with a name 
beginning with save 
execution( * save*(..) ) 
Any method defined by the 
EventDAO interface with 
one param 
execution( * pack.dao.EventDAO.*(*) 
) 
© Onkar Deshpande 
20
Spring 
© Onkar Deshpande 
21
Thank You 
© Onkar Deshpande 
22

More Related Content

What's hot

Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
Dzmitry Naskou
 
Aspect Oriented Programming
Aspect Oriented ProgrammingAspect Oriented Programming
Aspect Oriented Programming
Rajesh Ganesan
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
Harshit Choudhary
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
Jeevesh Pandey
 
React js
React jsReact js
Spring boot
Spring bootSpring boot
Spring boot
sdeeg
 
Building microservices sample application
Building microservices sample applicationBuilding microservices sample application
Building microservices sample application
Anil Allewar
 
WTF is Reactive Programming
WTF is Reactive ProgrammingWTF is Reactive Programming
WTF is Reactive Programming
Evgeny Poberezkin
 
Spring Core
Spring CoreSpring Core
Spring Core
Pushan Bhattacharya
 
Spring Webflux
Spring WebfluxSpring Webflux
Spring Webflux
Carlos E. Salazar
 
React Hooks
React HooksReact Hooks
React Hooks
Joao Marins
 
Spring Boot
Spring BootSpring Boot
Spring Boot
Jaran Flaath
 
Spring boot
Spring bootSpring boot
Spring boot
Bhagwat Kumar
 
우아한 모노리스
우아한 모노리스우아한 모노리스
우아한 모노리스
Arawn Park
 
Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans
Hitesh-Java
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Serhat Can
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
Rasheed Waraich
 
Reactive programming intro
Reactive programming introReactive programming intro
Reactive programming intro
Ahmed Ehab AbdulAziz
 
React js programming concept
React js programming conceptReact js programming concept
React js programming concept
Tariqul islam
 

What's hot (20)

Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
 
Aspect Oriented Programming
Aspect Oriented ProgrammingAspect Oriented Programming
Aspect Oriented Programming
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 
React js
React jsReact js
React js
 
Spring boot
Spring bootSpring boot
Spring boot
 
Building microservices sample application
Building microservices sample applicationBuilding microservices sample application
Building microservices sample application
 
WTF is Reactive Programming
WTF is Reactive ProgrammingWTF is Reactive Programming
WTF is Reactive Programming
 
Spring Core
Spring CoreSpring Core
Spring Core
 
Spring Data JPA
Spring Data JPASpring Data JPA
Spring Data JPA
 
Spring Webflux
Spring WebfluxSpring Webflux
Spring Webflux
 
React Hooks
React HooksReact Hooks
React Hooks
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring boot
Spring bootSpring boot
Spring boot
 
우아한 모노리스
우아한 모노리스우아한 모노리스
우아한 모노리스
 
Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
Reactive programming intro
Reactive programming introReactive programming intro
Reactive programming intro
 
React js programming concept
React js programming conceptReact js programming concept
React js programming concept
 

Viewers also liked

Spring AOP
Spring AOPSpring AOP
Spring AOPcteguh
 
Spring AOP Introduction
Spring AOP IntroductionSpring AOP Introduction
Spring AOP Introductionb0ris_1
 
Aspect oriented programming_with_spring
Aspect oriented programming_with_springAspect oriented programming_with_spring
Aspect oriented programming_with_springGuo Albert
 
AOP
AOPAOP
Introduction to Aspect Oriented Programming
Introduction to Aspect Oriented ProgrammingIntroduction to Aspect Oriented Programming
Introduction to Aspect Oriented Programming
Yan Cui
 
Introduction to Aspect Oriented Programming
Introduction to Aspect Oriented ProgrammingIntroduction to Aspect Oriented Programming
Introduction to Aspect Oriented Programming
Amir Kost
 

Viewers also liked (6)

Spring AOP
Spring AOPSpring AOP
Spring AOP
 
Spring AOP Introduction
Spring AOP IntroductionSpring AOP Introduction
Spring AOP Introduction
 
Aspect oriented programming_with_spring
Aspect oriented programming_with_springAspect oriented programming_with_spring
Aspect oriented programming_with_spring
 
AOP
AOPAOP
AOP
 
Introduction to Aspect Oriented Programming
Introduction to Aspect Oriented ProgrammingIntroduction to Aspect Oriented Programming
Introduction to Aspect Oriented Programming
 
Introduction to Aspect Oriented Programming
Introduction to Aspect Oriented ProgrammingIntroduction to Aspect Oriented Programming
Introduction to Aspect Oriented Programming
 

Similar to Spring AOP in Nutshell

Spring AOP
Spring AOPSpring AOP
Spring - Part 3 - AOP
Spring - Part 3 - AOPSpring - Part 3 - AOP
Spring - Part 3 - AOP
Hitesh-Java
 
Session 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOPSession 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOP
PawanMM
 
Spring AOP
Spring AOPSpring AOP
Spring AOP
AnushaNaidu
 
Performance analysis of synchronisation problem
Performance analysis of synchronisation problemPerformance analysis of synchronisation problem
Performance analysis of synchronisation problem
harshit200793
 
Spring aop
Spring aopSpring aop
Spring aop
Hamid Ghorbani
 
WoMakersCode 2016 - Shit Happens
WoMakersCode 2016 -  Shit HappensWoMakersCode 2016 -  Shit Happens
WoMakersCode 2016 - Shit Happens
Jackson F. de A. Mafra
 
Aspect Oriented Software Development
Aspect Oriented Software DevelopmentAspect Oriented Software Development
Aspect Oriented Software DevelopmentJignesh Patel
 
Adop and maintenance task presentation 151015
Adop and maintenance task presentation 151015Adop and maintenance task presentation 151015
Adop and maintenance task presentation 151015
andreas kuncoro
 
Aspect-oriented programming in Perl
Aspect-oriented programming in PerlAspect-oriented programming in Perl
Aspect-oriented programming in Perl
megakott
 
C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2Hammad Rajjoub
 
C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2
Hammad Rajjoub
 
Aspect Oriented Programming
Aspect Oriented ProgrammingAspect Oriented Programming
Aspect Oriented Programming
Shreya Chatterjee
 
Simplifying RCP Update and Install
Simplifying RCP Update and InstallSimplifying RCP Update and Install
Simplifying RCP Update and Install
susanfmccourt
 
Software Development Standard Operating Procedure
Software Development Standard Operating Procedure Software Development Standard Operating Procedure
Software Development Standard Operating Procedure
rupeshchanchal
 
Open-Do - Initial concepts and idea
Open-Do - Initial concepts and ideaOpen-Do - Initial concepts and idea
Open-Do - Initial concepts and idea
AdaCore
 
Spring batch overivew
Spring batch overivewSpring batch overivew
Spring batch overivew
Chanyeong Choi
 
spring aop
spring aopspring aop
spring aop
Kalyani Patil
 
Spring aop concepts
Spring aop conceptsSpring aop concepts
Spring aop concepts
RushiBShah
 

Similar to Spring AOP in Nutshell (20)

Spring AOP
Spring AOPSpring AOP
Spring AOP
 
Spring - Part 3 - AOP
Spring - Part 3 - AOPSpring - Part 3 - AOP
Spring - Part 3 - AOP
 
Session 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOPSession 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOP
 
Spring AOP
Spring AOPSpring AOP
Spring AOP
 
Performance analysis of synchronisation problem
Performance analysis of synchronisation problemPerformance analysis of synchronisation problem
Performance analysis of synchronisation problem
 
Spring aop
Spring aopSpring aop
Spring aop
 
WoMakersCode 2016 - Shit Happens
WoMakersCode 2016 -  Shit HappensWoMakersCode 2016 -  Shit Happens
WoMakersCode 2016 - Shit Happens
 
Aspect Oriented Software Development
Aspect Oriented Software DevelopmentAspect Oriented Software Development
Aspect Oriented Software Development
 
Adop and maintenance task presentation 151015
Adop and maintenance task presentation 151015Adop and maintenance task presentation 151015
Adop and maintenance task presentation 151015
 
Aspect-oriented programming in Perl
Aspect-oriented programming in PerlAspect-oriented programming in Perl
Aspect-oriented programming in Perl
 
Intro To AOP
Intro To AOPIntro To AOP
Intro To AOP
 
C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2
 
C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2
 
Aspect Oriented Programming
Aspect Oriented ProgrammingAspect Oriented Programming
Aspect Oriented Programming
 
Simplifying RCP Update and Install
Simplifying RCP Update and InstallSimplifying RCP Update and Install
Simplifying RCP Update and Install
 
Software Development Standard Operating Procedure
Software Development Standard Operating Procedure Software Development Standard Operating Procedure
Software Development Standard Operating Procedure
 
Open-Do - Initial concepts and idea
Open-Do - Initial concepts and ideaOpen-Do - Initial concepts and idea
Open-Do - Initial concepts and idea
 
Spring batch overivew
Spring batch overivewSpring batch overivew
Spring batch overivew
 
spring aop
spring aopspring aop
spring aop
 
Spring aop concepts
Spring aop conceptsSpring aop concepts
Spring aop concepts
 

Recently uploaded

Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 

Recently uploaded (20)

Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 

Spring AOP in Nutshell

  • 1. Spring AOP Onkar Deshpande © Onkar Deshpande 1
  • 2. Agenda Understanding cross cutting concerns Need of AOP Aspect-oriented programming concepts AOP Terminologies Implementing aspect behavior AspectJ APIs and annotations Spring AOP application © Onkar Deshpande 2
  • 3. Functional Programming © Onkar Deshpande 3
  • 4. Object Oriented Programming © Onkar Deshpande 4
  • 5. Problem in OOP © Onkar Deshpande 5
  • 6. Object Oriented Solution © Onkar Deshpande 6
  • 7. Problem in solution provided by OOP An aspect is scattered or tangled as code Making it harder to understand and maintain To many relationship with cross-cutting concerns OOP creates a coupling between core and crosscutting concerns. This causes  Leads to duplicated code  Hard to maintain code  Hard to use code © Onkar Deshpande 7
  • 8. Better Solution Logging Transaction Aspect Configuration © Onkar Deshpande 8
  • 9. Advantages of this approach Increase the modularity By allowing separating cross-cutting concerns from business logic Making easy to understand and maintain Spring AOP will take care of calling concerns, we just need to declare about concerns once in configuration file  You can focus on the concerns at one place  Easier to add and remove concerns  Easier to modify or fine tune concerns  Easier to understand  Efficient to implement  More efficient © Onkar Deshpande 9
  • 10. What Is AOP Aspect-oriented programming, or AOP, is a programming technique that allows programmers to modularize crosscutting concerns It is often defined as a programming technique that promotes separation of crosscutting concerns with in a software system concerns : A concern is a particular issue, concept, or area of interest for an application: typically, a goal the application must meet © Onkar Deshpande 10
  • 11. Cross-cutting concerns The systems or concerns that tend to cut across multiple components in a system are referred as Cross-cutting concerns System wide concerns that span multiple modules. Cuts across the typical division of responsibility. Examples such as  Transaction Management  Security  Logging © Onkar Deshpande 11
  • 12. Cross Cutting Concerns in OOP Cont.. public class Account { public void deposit() { // Transaction Management // Logging // Checking for the Privileged User // Actual Deposit Logic comes here } public void withdraw() { // Transaction Management // Logging // Checking for the Privileged User // Actual Withdraw Logic comes here } } AOP calls this kind of logic that cross-cuts the existing business logic as Cross-Cutting Concerns © Onkar Deshpande 12
  • 13. AOP vs OOP Object Oriented Aspect Oriented Class – code unit that encapsulates methods and attributes Aspect – code unit that encapsulates pointcuts, advice, and attributes Method signatures – define the entry points for the execution of method bodies Pointcut – define the set of entry points (triggers) in which advice is executed Method bodies – implementations of the primary concerns Advice – implementations of the cross cutting concerns Compiler – converts source code into object code Weaver – instruments code (source or object) with advice © Onkar Deshpande 13
  • 14. AOP Terminologies Terms Description Aspect A module which has a set of APIs providing cross-cutting requirements. For example, a logging module would be called AOP aspect for logging. An application can have any number of aspects depending on the requirement Join Point This represents a point in your application where you can plug-in AOP aspect. You can also say, it is the actual place in the application where an action will be taken using Spring AOP framework Advice This is the actual action to be taken either before or after the method execution. This is actual piece of code that is invoked during program execution by Spring AOP framework Pointcut This is a set of one or more join points where an advice should be executed. You can specify point cuts using expressions or patterns as we will see in our AOP examples © Onkar Deshpande 14
  • 15. AOP Terminologies Transaction Advice Method1 Method2 Method3 Logging Advisor Join Point © Onkar Deshpande 15
  • 16. Types of Advice Advice Description before Run advice before the a method execution after Run advice after the a method execution regardless of its outcome after-returning Run advice after the a method execution only if method completes successfully after-throwing Run advice after the a method execution only if method exits by throwing an exception Around Run advice before and after the advised method is invoked © Onkar Deshpande 16
  • 17. Declaring an aspect A concern that cuts across multiple classses and layers import org.aspectj.lang.annotation.Aspect; @Aspect public class LoggingInterceptor { // ... } © Onkar Deshpande 17
  • 18. Declaring a pointcut An expression mapped to a join point (method invocation) @Aspect Public class LoggingInterceptor { @Pointcut( "execution( * pack.dao.*.*(..) )" ) private void daoLayer() { // code } } © Onkar Deshpande 18
  • 19. Pointcut expression pattern The execution pointcut designator is used most often © Onkar Deshpande 19
  • 20. Pointcut expression examples Description Pointcut Any public method execution( public * *(..) ) Any public method defined in the dao package execution( public * pack.dao.*.*(..) ) Any method with a name beginning with save execution( * save*(..) ) Any method defined by the EventDAO interface with one param execution( * pack.dao.EventDAO.*(*) ) © Onkar Deshpande 20
  • 21. Spring © Onkar Deshpande 21
  • 22. Thank You © Onkar Deshpande 22