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
Ad

More Related Content

What's hot (20)

Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
Jonathan Holloway
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
guest11106b
 
Spring ppt
Spring pptSpring ppt
Spring ppt
Mumbai Academisc
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
Pravin Pundge
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
Purbarun Chakrabarti
 
Spring Framework - MVC
Spring Framework - MVCSpring Framework - MVC
Spring Framework - MVC
Dzmitry Naskou
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
Hamid Ghorbani
 
Spring framework aop
Spring framework aopSpring framework aop
Spring framework aop
Taemon Piya-Lumyong
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
NexThoughts Technologies
 
.Net Core
.Net Core.Net Core
.Net Core
Bertrand Le Roy
 
Spring boot
Spring bootSpring boot
Spring boot
Bhagwat Kumar
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Hùng Nguyễn Huy
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
nomykk
 
Spring Web MVC
Spring Web MVCSpring Web MVC
Spring Web MVC
zeeshanhanif
 
Java Spring Framework
Java Spring FrameworkJava Spring Framework
Java Spring Framework
Mehul Jariwala
 
Spring framework core
Spring framework coreSpring framework core
Spring framework core
Taemon Piya-Lumyong
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
tola99
 
Spring Boot
Spring BootSpring Boot
Spring Boot
HongSeong Jeon
 
Spring annotation
Spring annotationSpring annotation
Spring annotation
Rajiv Srivastava
 
Spring Boot
Spring BootSpring Boot
Spring Boot
Jiayun Zhou
 

Viewers also liked (6)

Spring AOP
Spring AOPSpring AOP
Spring AOP
cteguh
 
Spring AOP Introduction
Spring AOP IntroductionSpring AOP Introduction
Spring AOP Introduction
b0ris_1
 
Aspect oriented programming_with_spring
Aspect oriented programming_with_springAspect oriented programming_with_spring
Aspect oriented programming_with_spring
Guo Albert
 
AOP
AOPAOP
AOP
Joshua Yoon
 
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
 
Spring AOP
Spring AOPSpring AOP
Spring AOP
cteguh
 
Spring AOP Introduction
Spring AOP IntroductionSpring AOP Introduction
Spring AOP Introduction
b0ris_1
 
Aspect oriented programming_with_spring
Aspect oriented programming_with_springAspect oriented programming_with_spring
Aspect oriented programming_with_spring
Guo Albert
 
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
 
Ad

Similar to Spring AOP in Nutshell (20)

Spring AOP
Spring AOPSpring AOP
Spring AOP
Radhakrishna Mutthoju
 
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 Programming
Aspect Oriented ProgrammingAspect Oriented Programming
Aspect Oriented Programming
Rajesh Ganesan
 
Programming C ppt for learning foundations
Programming C ppt for learning foundationsProgramming C ppt for learning foundations
Programming C ppt for learning foundations
ssuser65733f
 
AOP (Aspect-Oriented Programming) spring boot
AOP (Aspect-Oriented Programming) spring bootAOP (Aspect-Oriented Programming) spring boot
AOP (Aspect-Oriented Programming) spring boot
PLAYAFIFI
 
Aspect Oriented Software Development
Aspect Oriented Software DevelopmentAspect Oriented Software Development
Aspect Oriented Software Development
Jignesh 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
 
Intro To AOP
Intro To AOPIntro To AOP
Intro To AOP
elliando dias
 
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
 
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 - 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
 
Performance analysis of synchronisation problem
Performance analysis of synchronisation problemPerformance analysis of synchronisation problem
Performance analysis of synchronisation problem
harshit200793
 
Aspect Oriented Programming
Aspect Oriented ProgrammingAspect Oriented Programming
Aspect Oriented Programming
Rajesh Ganesan
 
Programming C ppt for learning foundations
Programming C ppt for learning foundationsProgramming C ppt for learning foundations
Programming C ppt for learning foundations
ssuser65733f
 
AOP (Aspect-Oriented Programming) spring boot
AOP (Aspect-Oriented Programming) spring bootAOP (Aspect-Oriented Programming) spring boot
AOP (Aspect-Oriented Programming) spring boot
PLAYAFIFI
 
Aspect Oriented Software Development
Aspect Oriented Software DevelopmentAspect Oriented Software Development
Aspect Oriented Software Development
Jignesh 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 2
Hammad 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
 
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
 
Ad

Recently uploaded (20)

Solidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license codeSolidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license code
aneelaramzan63
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
EASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License CodeEASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License Code
aneelaramzan63
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025
kashifyounis067
 
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Ranjan Baisak
 
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New VersionPixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
saimabibi60507
 
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Andre Hora
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
Download Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With LatestDownload Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With Latest
tahirabibi60507
 
Solidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license codeSolidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license code
aneelaramzan63
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
EASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License CodeEASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License Code
aneelaramzan63
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025
kashifyounis067
 
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Ranjan Baisak
 
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New VersionPixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
saimabibi60507
 
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Andre Hora
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
Download Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With LatestDownload Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With Latest
tahirabibi60507
 

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