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
PPTX
Optimica Testing Toolkit
PDF
Efficient Methodology of Sampling UVM RAL During Simulation for SoC Functiona...
PPTX
Model Testing Toolkit - Overview
PPTX
Procter & Gamble Modelon INCOSE 2017
PDF
Automated Testing of Hybrid Simulink/Stateflow Controllers
PPTX
Multi-core Real-time Simulation of High-Fidelity Vehicle Models using Open St...
Code Management Workshop
Optimica Testing Toolkit
Efficient Methodology of Sampling UVM RAL During Simulation for SoC Functiona...
Model Testing Toolkit - Overview
Procter & Gamble Modelon INCOSE 2017
Automated Testing of Hybrid Simulink/Stateflow Controllers
Multi-core Real-time Simulation of High-Fidelity Vehicle Models using Open St...

What's hot (6)

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

Similar to Spring AOP (20)

PPTX
Session 45 - Spring - Part 3 - AOP
PPSX
Spring - Part 3 - AOP
PPTX
Spring aop
PPTX
Spring AOP in Nutshell
PDF
AOP (Aspect-Oriented Programming) spring boot
PPTX
Aspect Oriented Programming
PPTX
Spring framework AOP
PPTX
Introduction to Aspect Oriented Programming
PPTX
Introduction to Spring
PPTX
spring aop
PPT
Aop spring
PPTX
Spring aop concepts
PPTX
Aspect Oriented Programming: Hidden Toolkit That You Already Have
PPTX
Spring 1 day program
PPTX
Spring framework part 2
PPTX
Aspect Oriented Programming
PPTX
Software Engineering Chapter 4 Part 1 Euu
PPTX
Performance analysis of synchronisation problem
PDF
Spring batch overivew
PDF
Angular meetup 2 2019-08-29
Session 45 - Spring - Part 3 - AOP
Spring - Part 3 - AOP
Spring aop
Spring AOP in Nutshell
AOP (Aspect-Oriented Programming) spring boot
Aspect Oriented Programming
Spring framework AOP
Introduction to Aspect Oriented Programming
Introduction to Spring
spring aop
Aop spring
Spring aop concepts
Aspect Oriented Programming: Hidden Toolkit That You Already Have
Spring 1 day program
Spring framework part 2
Aspect Oriented Programming
Software Engineering Chapter 4 Part 1 Euu
Performance analysis of synchronisation problem
Spring batch overivew
Angular meetup 2 2019-08-29
Ad

Recently uploaded (20)

PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Autodesk AutoCAD Crack Free Download 2025
PDF
Download FL Studio Crack Latest version 2025 ?
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Transform Your Business with a Software ERP System
PDF
medical staffing services at VALiNTRY
PDF
iTop VPN 6.5.0 Crack + License Key 2025 (Premium Version)
PPTX
Monitoring Stack: Grafana, Loki & Promtail
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
AutoCAD Professional Crack 2025 With License Key
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Complete Guide to Website Development in Malaysia for SMEs
DOCX
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Wondershare Filmora 15 Crack With Activation Key [2025
Autodesk AutoCAD Crack Free Download 2025
Download FL Studio Crack Latest version 2025 ?
Navsoft: AI-Powered Business Solutions & Custom Software Development
Transform Your Business with a Software ERP System
medical staffing services at VALiNTRY
iTop VPN 6.5.0 Crack + License Key 2025 (Premium Version)
Monitoring Stack: Grafana, Loki & Promtail
Operating system designcfffgfgggggggvggggggggg
Odoo Companies in India – Driving Business Transformation.pdf
AutoCAD Professional Crack 2025 With License Key
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
How to Choose the Right IT Partner for Your Business in Malaysia
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
Reimagine Home Health with the Power of Agentic AI​
Complete Guide to Website Development in Malaysia for SMEs
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps

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.