7/30/2019 Venkat Spring AOP
1/14
SPRING AOP
Venkat Krishnan
7/30/2019 Venkat Spring AOP
2/14
AOP CONCEPT
Aspect-Oriented Programming(AOP)
complements OOP by providing another way ofthinking about program structure.
While OO decomposes applications into a
20/11/2012Venkat Krishnan
,into aspects or concerns.
This enables modularization of concerns such as
transaction management that would otherwise
cut across multiple objects. (Such concerns areoften termed crosscuttingconcerns.)
7/30/2019 Venkat Spring AOP
3/14
AOP CONCEPT
20/11/2012Venkat Krishnan
Aspects modularize crosscutting concerns, applying logic that
spans multiple application objects.
7/30/2019 Venkat Spring AOP
4/14
SPRING AOP FRAMEWORK
One of the key components of Spring is the
AOP framework. AOP complements Spring IoC to provide a
very capable middleware solution.
20/11/2012Venkat Krishnan
To provide declarative enterprise services,
especially as a replacement for EJB declarativeservices. The most important such service isdeclarative transaction management, whichbuilds on Spring's transaction abstraction.
7/30/2019 Venkat Spring AOP
5/14
SPRING AOP FRAMEWORK
To allow users to implement custom aspects,
complementing their use of OOP with AOP.
Thus you can view Spring AOP as either an
20/11/2012Venkat Krishnan
provide declarative transaction
management without EJB; or use the full
power of the Spring AOP framework toimplement custom aspects.
7/30/2019 Venkat Spring AOP
6/14
AOP TERMINOLOGY
Aspect:
A modularization of a concern for which the
implementation might otherwise cut across
multi le ob ects.
20/11/2012Venkat Krishnan
Transaction management is a good example of a
crosscutting concern in J2EE applications.
Aspects are implemented using Spring as
Advisors or interceptors.
7/30/2019 Venkat Spring AOP
7/14
AOP TERMINOLOGY
Joinpoint:
Point during the execution of a program, such asa method invocation or a particular exceptionbeing thrown.
In S rin AOP a oin oint is method invocation.
20/11/2012Venkat Krishnan
Spring does not use the term joinpointprominently; joinpoint information is accessiblethrough methods on the MethodInvocationargument passed to interceptors, and is
evaluated by implementations of theorg.springframework.aop.Pointcut interface.
7/30/2019 Venkat Spring AOP
8/14
AOP TERMINOLOGY
Advice:
Action taken by the AOP framework at a
particular joinpoint.
Different t es of advice include "around "
20/11/2012Venkat Krishnan
"before" and "throws" advice.
Spring models an advice as an interceptor,
maintaining a chain of interceptors "around" the
joinpoint.
7/30/2019 Venkat Spring AOP
9/14
AOP TERMINOLOGY
Pointcut:
A set of joinpoints specifying when an advice
should fire.
20/11/2012Venkat Krishnan
specify pointcuts: for example, using regular
expressions.
7/30/2019 Venkat Spring AOP
10/14
AOP TERMINOLOGY
Target object:
Object containing the joinpoint.
Also referred to as advised or proxied object.
20/11/2012Venkat Krishnan
proxy:Object created by the AOP framework, including
advice.
In Spring, an AOP proxy will be a JDK dynamicproxy or a CGLIB proxy.
7/30/2019 Venkat Spring AOP
11/14
SPRING AOP
20/11/2012Venkat Krishnan
Spring aspects are implemented as proxies that wrap the target object.
The proxy handles method calls, performs additional aspect logic, and
then invokes the target method.
7/30/2019 Venkat Spring AOP
12/14
SPRING ADVICES
Different advice types include:
Around advice:org.aopalliance.intercept.MethodInterceptor
20/11/2012Venkat Krishnan
org.springframework.aop.MethodBeforeAdvice
After throwing advice:org.springframework.aop.ThrowsAdvice
After returning advice:org.springframework.aop.AfterReturningAdvice
7/30/2019 Venkat Spring AOP
13/14
CONCEPT
Spring provides classes to represent
pointcuts and different advice types.
Spring uses the term advisorfor an object
20/11/2012Venkat Krishnan
represen ng an aspec , nc u ng o anadvice and a pointcut targeting it to specific
joinpoints.
7/30/2019 Venkat Spring AOP
14/14
20/11/2012Venkat Krishnan