SlideShare a Scribd company logo
Spring AOP
Radhakrishna M
Agenda
• What is AOP?
• Why it is required?
• AOP concepts
• Types of Advices
• Configuration
• Advantages
• Conclusion
Aspect – A general feature that is applied globally
to an application (logging, performance monitoring,
exception handling, transaction management, etc).
Concern: AOP breaks the program logic into distinct
parts (called concerns).
cross-cutting concern : A cross-cutting concern is a
concern that can affect the whole application and
should be centralized in one location in code as
possible, such as transaction management,
authentication, logging, security etc.
Aspect oriented programming
• Aspect Oriented Programming (AOP) refers to
the programming paradigm which isolates
secondary or supporting functions from the
main program’s business logic.
• It provides the pluggable way to dynamically
add the additional concern before, after or
around the actual logic.
Need for AOP
Scenario: Maintain log and send notification after calling
methods that starts from m.
class A{
public void m1(){...}
public void m2(){...}
public void m3(){...}
public void n1(){...}
public void n2(){...}
public void p1(){...}
public void p2(){...}
}
Solution with AOP: We don't have to call methods from the
method. Now we can define the additional concern like
maintaining log, sending notification etc. in the method of a class.
Its entry is given in the xml file.
public logAndNotify(){
……………………..
……………………..
}
Before AOP
Timecard
Transaction
Security
Scheduling
Transaction
Security
Financial
Transaction
Security
Crosscutting Concerns
After AOP
Timecard SchedulingFinancial
Transaction Security
Aspects
• In AOP crosscutting concerns are implemented in
aspects instead of fusing them into core modules.
• Aspects are an additional unit of modularity.
• Aspects can be reused.
• By reducing code tangling it makes it easier to
understand what the core functionality of a module
is.
AOP concepts
• Joinpoint – Defines a point during the execution of a
program.
• Advice – Action taken at a Joinpoint.
 Before Advice: It executes before a join point.
 After Returning Advice: It executes after a joint point
completes normally.
 After Throwing Advice: It executes if method exits by
throwing an exception.
 After (finally) Advice: It executes after a join point
regardless of join point exit whether normally or
exceptional return.
 Around Advice: It executes before and after a join point.
• Pointcut – Combination of joinpoints where the advice
need to be applied.
• Introduction – It means introduction of additional method
and fields for a type. It allows you to introduce new
interface to any advised object.
• Aspect – It is a class that contains advices, joinpoints etc.
• Interceptor – It is an aspect that contains only one advice.
• Weaving – It is the process of linking aspect with other
application types or objects to create an advised object.
Weaving can be done at compile time, load time or
runtime. Spring AOP performs weaving at runtime.
AOP Key Idea
base/core program
Aspects
weave
Final system
Hierarchy of advice interfaces
Spring AOP
AOP vs OOP
AOP
1. Aspect - Code unit that
encapsulates pointcuts,
advice and attributes.
2. Pointcut – define the set of
entry points(triggers)
in which advice is executed.
3. Advice – Implementation of
cross cutting concern
4. Weaver – Construct
code(source /object) with
advice.
OOP
1. Class – Code unit that
encapsulates methods and
attributes
2. Method signature – Define
the entry points for the
execution of method bodies
3. Method bodies-
Implementation of the
business logic concerns
4. Compiler – Convert source
code to object code.
Configuration
1. Create a Aspect with the required logic:
<bean id="customerAspect" class="com.jcms.jms.CustomerAspect“/>
<aop:aspect ref="customerAspect">
2 . Declare pointcuts :
<aop:pointcut id="customerPoint" expression="execution(*
com.jcms.biz.AccountService.saveAccount(..)) " />
3. Declare advices:
<aop:after pointcut-ref="customerPoint" method="log" />
<aop:before pointcut-ref="customerPoint"
method="setChangeHistoryId"/>
Advantages
Better separates processes (concerns) than
previous approaches.
Creates cleaner code.
Properly separates business requirements into
clean reusable code.
Code is reusable at a greater extent than OOP.
Conclusion
• Important to remember that AOP is not
replacing OOP, but it enhancing the features
of OOP with a new methodology.
Thank you

More Related Content

PDF
Code Management Workshop
Sameh El-Ashry
 
PPTX
Optimica Testing Toolkit
Modelon
 
PDF
Efficient Methodology of Sampling UVM RAL During Simulation for SoC Functiona...
Sameh El-Ashry
 
PPTX
Model Testing Toolkit - Overview
Modelon
 
PPTX
Procter & Gamble Modelon INCOSE 2017
Modelon
 
PDF
Automated Testing of Hybrid Simulink/Stateflow Controllers
Lionel Briand
 
PPTX
Multi-core Real-time Simulation of High-Fidelity Vehicle Models using Open St...
Modelon
 
Code Management Workshop
Sameh El-Ashry
 
Optimica Testing Toolkit
Modelon
 
Efficient Methodology of Sampling UVM RAL During Simulation for SoC Functiona...
Sameh El-Ashry
 
Model Testing Toolkit - Overview
Modelon
 
Procter & Gamble Modelon INCOSE 2017
Modelon
 
Automated Testing of Hybrid Simulink/Stateflow Controllers
Lionel Briand
 
Multi-core Real-time Simulation of High-Fidelity Vehicle Models using Open St...
Modelon
 

What's hot (6)

PDF
verification_planning_systemverilog_uvm_2020
Sameh El-Ashry
 
PPTX
Instruction set of 8085
ThamizhselviKrishnam
 
PDF
When Should I use Simulation?
SIMUL8 Corporation
 
PDF
Modelon FMI Tutorial NAMUG 2016
Modelon
 
PPTX
Model based design-Hardware in loop-software in loop
Mahmoud Hussein
 
PPTX
Using Modelica and FMI to evaluate requirements compliance early in system d...
Modelon
 
verification_planning_systemverilog_uvm_2020
Sameh El-Ashry
 
Instruction set of 8085
ThamizhselviKrishnam
 
When Should I use Simulation?
SIMUL8 Corporation
 
Modelon FMI Tutorial NAMUG 2016
Modelon
 
Model based design-Hardware in loop-software in loop
Mahmoud Hussein
 
Using Modelica and FMI to evaluate requirements compliance early in system d...
Modelon
 
Ad

Similar to Spring AOP (20)

PPTX
Session 45 - Spring - Part 3 - AOP
PawanMM
 
PPSX
Spring - Part 3 - AOP
Hitesh-Java
 
PPTX
Spring aop
sanskriti agarwal
 
PPTX
Spring AOP in Nutshell
Onkar Deshpande
 
PDF
AOP (Aspect-Oriented Programming) spring boot
PLAYAFIFI
 
PPTX
Aspect Oriented Programming
Rajesh Ganesan
 
PPTX
Spring framework AOP
Anuj Singh Rajput
 
PPTX
Introduction to Aspect Oriented Programming
Amir Kost
 
PPTX
Introduction to Spring
Sujit Kumar
 
PPTX
spring aop
Kalyani Patil
 
PPT
Aop spring
chamilavt
 
PPTX
Spring aop concepts
RushiBShah
 
PPTX
Aspect Oriented Programming: Hidden Toolkit That You Already Have
Salesforce Engineering
 
PPTX
Spring 1 day program
Mohit Kanwar
 
PPTX
Spring framework part 2
Skillwise Group
 
PPTX
Aspect Oriented Programming
Shreya Chatterjee
 
PPTX
Software Engineering Chapter 4 Part 1 Euu
CryptoMaster7
 
PPTX
Performance analysis of synchronisation problem
harshit200793
 
PDF
Spring batch overivew
Chanyeong Choi
 
PDF
Angular meetup 2 2019-08-29
Nitin Bhojwani
 
Session 45 - Spring - Part 3 - AOP
PawanMM
 
Spring - Part 3 - AOP
Hitesh-Java
 
Spring aop
sanskriti agarwal
 
Spring AOP in Nutshell
Onkar Deshpande
 
AOP (Aspect-Oriented Programming) spring boot
PLAYAFIFI
 
Aspect Oriented Programming
Rajesh Ganesan
 
Spring framework AOP
Anuj Singh Rajput
 
Introduction to Aspect Oriented Programming
Amir Kost
 
Introduction to Spring
Sujit Kumar
 
spring aop
Kalyani Patil
 
Aop spring
chamilavt
 
Spring aop concepts
RushiBShah
 
Aspect Oriented Programming: Hidden Toolkit That You Already Have
Salesforce Engineering
 
Spring 1 day program
Mohit Kanwar
 
Spring framework part 2
Skillwise Group
 
Aspect Oriented Programming
Shreya Chatterjee
 
Software Engineering Chapter 4 Part 1 Euu
CryptoMaster7
 
Performance analysis of synchronisation problem
harshit200793
 
Spring batch overivew
Chanyeong Choi
 
Angular meetup 2 2019-08-29
Nitin Bhojwani
 
Ad

Recently uploaded (20)

PDF
Summary Of Odoo 18.1 to 18.4 : The Way For Odoo 19
CandidRoot Solutions Private Limited
 
PPTX
Role Of Python In Programing Language.pptx
jaykoshti048
 
PDF
Balancing Resource Capacity and Workloads with OnePlan – Avoid Overloading Te...
OnePlan Solutions
 
PPTX
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
PDF
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
PPTX
Contractor Management Platform and Software Solution for Compliance
SHEQ Network Limited
 
PPTX
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
PDF
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
PDF
Salesforce Implementation Services Provider.pdf
VALiNTRY360
 
PPTX
GALILEO CRS SYSTEM | GALILEO TRAVEL SOFTWARE
philipnathen82
 
PPTX
Presentation about Database and Database Administrator
abhishekchauhan86963
 
PDF
Immersive experiences: what Pharo users do!
ESUG
 
PPTX
Explanation about Structures in C language.pptx
Veeral Rathod
 
PPTX
ConcordeApp: Engineering Global Impact & Unlocking Billions in Event ROI with AI
chastechaste14
 
DOCX
Can You Build Dashboards Using Open Source Visualization Tool.docx
Varsha Nayak
 
PPTX
Can You Build Dashboards Using Open Source Visualization Tool.pptx
Varsha Nayak
 
PDF
Protecting the Digital World Cyber Securit
dnthakkar16
 
PDF
Exploring AI Agents in Process Industries
amoreira6
 
PPT
Why Reliable Server Maintenance Service in New York is Crucial for Your Business
Sam Vohra
 
PPTX
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
Summary Of Odoo 18.1 to 18.4 : The Way For Odoo 19
CandidRoot Solutions Private Limited
 
Role Of Python In Programing Language.pptx
jaykoshti048
 
Balancing Resource Capacity and Workloads with OnePlan – Avoid Overloading Te...
OnePlan Solutions
 
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
Contractor Management Platform and Software Solution for Compliance
SHEQ Network Limited
 
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
Salesforce Implementation Services Provider.pdf
VALiNTRY360
 
GALILEO CRS SYSTEM | GALILEO TRAVEL SOFTWARE
philipnathen82
 
Presentation about Database and Database Administrator
abhishekchauhan86963
 
Immersive experiences: what Pharo users do!
ESUG
 
Explanation about Structures in C language.pptx
Veeral Rathod
 
ConcordeApp: Engineering Global Impact & Unlocking Billions in Event ROI with AI
chastechaste14
 
Can You Build Dashboards Using Open Source Visualization Tool.docx
Varsha Nayak
 
Can You Build Dashboards Using Open Source Visualization Tool.pptx
Varsha Nayak
 
Protecting the Digital World Cyber Securit
dnthakkar16
 
Exploring AI Agents in Process Industries
amoreira6
 
Why Reliable Server Maintenance Service in New York is Crucial for Your Business
Sam Vohra
 
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 

Spring AOP

  • 2. Agenda • What is AOP? • Why it is required? • AOP concepts • Types of Advices • Configuration • Advantages • Conclusion
  • 3. Aspect – A general feature that is applied globally to an application (logging, performance monitoring, exception handling, transaction management, etc). Concern: AOP breaks the program logic into distinct parts (called concerns). cross-cutting concern : A cross-cutting concern is a concern that can affect the whole application and should be centralized in one location in code as possible, such as transaction management, authentication, logging, security etc.
  • 4. Aspect oriented programming • Aspect Oriented Programming (AOP) refers to the programming paradigm which isolates secondary or supporting functions from the main program’s business logic. • It provides the pluggable way to dynamically add the additional concern before, after or around the actual logic.
  • 5. Need for AOP Scenario: Maintain log and send notification after calling methods that starts from m. class A{ public void m1(){...} public void m2(){...} public void m3(){...} public void n1(){...} public void n2(){...} public void p1(){...} public void p2(){...} } Solution with AOP: We don't have to call methods from the method. Now we can define the additional concern like maintaining log, sending notification etc. in the method of a class. Its entry is given in the xml file. public logAndNotify(){ …………………….. …………………….. }
  • 7. Aspects • In AOP crosscutting concerns are implemented in aspects instead of fusing them into core modules. • Aspects are an additional unit of modularity. • Aspects can be reused. • By reducing code tangling it makes it easier to understand what the core functionality of a module is.
  • 8. AOP concepts • Joinpoint – Defines a point during the execution of a program. • Advice – Action taken at a Joinpoint.  Before Advice: It executes before a join point.  After Returning Advice: It executes after a joint point completes normally.  After Throwing Advice: It executes if method exits by throwing an exception.  After (finally) Advice: It executes after a join point regardless of join point exit whether normally or exceptional return.  Around Advice: It executes before and after a join point.
  • 9. • Pointcut – Combination of joinpoints where the advice need to be applied. • Introduction – It means introduction of additional method and fields for a type. It allows you to introduce new interface to any advised object. • Aspect – It is a class that contains advices, joinpoints etc. • Interceptor – It is an aspect that contains only one advice. • Weaving – It is the process of linking aspect with other application types or objects to create an advised object. Weaving can be done at compile time, load time or runtime. Spring AOP performs weaving at runtime.
  • 10. AOP Key Idea base/core program Aspects weave Final system
  • 11. Hierarchy of advice interfaces
  • 13. AOP vs OOP AOP 1. Aspect - Code unit that encapsulates pointcuts, advice and attributes. 2. Pointcut – define the set of entry points(triggers) in which advice is executed. 3. Advice – Implementation of cross cutting concern 4. Weaver – Construct code(source /object) with advice. OOP 1. Class – Code unit that encapsulates methods and attributes 2. Method signature – Define the entry points for the execution of method bodies 3. Method bodies- Implementation of the business logic concerns 4. Compiler – Convert source code to object code.
  • 14. Configuration 1. Create a Aspect with the required logic: <bean id="customerAspect" class="com.jcms.jms.CustomerAspect“/> <aop:aspect ref="customerAspect"> 2 . Declare pointcuts : <aop:pointcut id="customerPoint" expression="execution(* com.jcms.biz.AccountService.saveAccount(..)) " /> 3. Declare advices: <aop:after pointcut-ref="customerPoint" method="log" /> <aop:before pointcut-ref="customerPoint" method="setChangeHistoryId"/>
  • 15. Advantages Better separates processes (concerns) than previous approaches. Creates cleaner code. Properly separates business requirements into clean reusable code. Code is reusable at a greater extent than OOP.
  • 16. Conclusion • Important to remember that AOP is not replacing OOP, but it enhancing the features of OOP with a new methodology.