SlideShare a Scribd company logo
1 of 17
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
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

What's hot

What's hot (6)

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

Similar to Spring AOP

Introduction to Spring
Introduction to SpringIntroduction to Spring
Introduction to Spring
Sujit Kumar
 
Weaving aspects in PHP with the help of Go! AOP library
Weaving aspects in PHP with the help of Go! AOP libraryWeaving aspects in PHP with the help of Go! AOP library
Weaving aspects in PHP with the help of Go! AOP library
Alexander Lisachenko
 

Similar to Spring AOP (20)

Session 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOPSession 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOP
 
Spring - Part 3 - AOP
Spring - Part 3 - AOPSpring - Part 3 - AOP
Spring - Part 3 - AOP
 
Spring aop
Spring aopSpring aop
Spring aop
 
Spring AOP in Nutshell
Spring AOP in Nutshell Spring AOP in Nutshell
Spring AOP in Nutshell
 
Aspect Oriented Programming
Aspect Oriented ProgrammingAspect Oriented Programming
Aspect Oriented Programming
 
Spring framework AOP
Spring framework  AOPSpring framework  AOP
Spring framework AOP
 
Introduction to Aspect Oriented Programming
Introduction to Aspect Oriented ProgrammingIntroduction to Aspect Oriented Programming
Introduction to Aspect Oriented Programming
 
Introduction to Spring
Introduction to SpringIntroduction to Spring
Introduction to Spring
 
spring aop
spring aopspring aop
spring aop
 
Aop spring
Aop springAop spring
Aop spring
 
Spring aop concepts
Spring aop conceptsSpring aop concepts
Spring aop concepts
 
Aspect Oriented Programming: Hidden Toolkit That You Already Have
Aspect Oriented Programming: Hidden Toolkit That You Already HaveAspect Oriented Programming: Hidden Toolkit That You Already Have
Aspect Oriented Programming: Hidden Toolkit That You Already Have
 
Spring 1 day program
Spring 1 day programSpring 1 day program
Spring 1 day program
 
Spring framework part 2
Spring framework  part 2Spring framework  part 2
Spring framework part 2
 
Aspect Oriented Programming
Aspect Oriented ProgrammingAspect Oriented Programming
Aspect Oriented Programming
 
Performance analysis of synchronisation problem
Performance analysis of synchronisation problemPerformance analysis of synchronisation problem
Performance analysis of synchronisation problem
 
Spring batch overivew
Spring batch overivewSpring batch overivew
Spring batch overivew
 
Angular meetup 2 2019-08-29
Angular meetup 2   2019-08-29Angular meetup 2   2019-08-29
Angular meetup 2 2019-08-29
 
AOP on Android
AOP on AndroidAOP on Android
AOP on Android
 
Weaving aspects in PHP with the help of Go! AOP library
Weaving aspects in PHP with the help of Go! AOP libraryWeaving aspects in PHP with the help of Go! AOP library
Weaving aspects in PHP with the help of Go! AOP library
 

Recently uploaded

%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 

Recently uploaded (20)

%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 

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
  • 12.
  • 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.