SPRING AOP

Venkat Krishnan

While OO decomposes applications into a hierarchy of objects. AOP decomposes programs into aspects or concerns.) Venkat Krishnan 20/11/2012 . (Such concerns are often termed crosscutting concerns.AOP CONCEPT Aspect-Oriented Programming (AOP) complements OOP by providing another way of thinking about program structure. This enables modularization of concerns such as transaction management that would otherwise cut across multiple objects.

Venkat Krishnan 20/11/2012 .AOP CONCEPT Aspects modularize crosscutting concerns. applying logic that spans multiple application objects.

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. The most important such service is declarative transaction management. which builds on Spring's transaction abstraction. especially as a replacement for EJB declarative services. AOP is used in Spring: To provide declarative enterprise services. Venkat Krishnan 20/11/2012 .

Thus you can view Spring AOP as either an enabling technology that allows Spring to provide declarative transaction management without EJB. Venkat Krishnan 20/11/2012 . complementing their use of OOP with AOP. or use the full power of the Spring AOP framework to implement custom aspects.SPRING AOP FRAMEWORK To allow users to implement custom aspects.

Aspects are implemented using Spring as Advisors or interceptors. Transaction management is a good example of a crosscutting concern in J2EE applications. Venkat Krishnan 20/11/2012 .AOP TERMINOLOGY Aspect: A modularization of a concern for which the implementation might otherwise cut across multiple objects.

Pointcut interface. In Spring AOP. joinpoint information is accessible through methods on the MethodInvocation argument passed to interceptors. Spring does not use the term joinpoint prominently. a joinpoint is method invocation.springframework.aop. and is evaluated by implementations of the org. Venkat Krishnan 20/11/2012 . such as a method invocation or a particular exception being thrown.AOP TERMINOLOGY Joinpoint: Point during the execution of a program.

Venkat Krishnan 20/11/2012 . Different types of advice include "around. maintaining a chain of interceptors "around" the joinpoint. Spring models an advice as an interceptor." "before" and "throws" advice.AOP TERMINOLOGY Advice: Action taken by the AOP framework at a particular joinpoint.

An AOP framework must allow developers to specify pointcuts: for example. Venkat Krishnan 20/11/2012 .AOP TERMINOLOGY Pointcut: A set of joinpoints specifying when an advice should fire. using regular expressions.

an AOP proxy will be a JDK dynamic proxy or a CGLIB proxy. Venkat Krishnan 20/11/2012 . In Spring. AOP proxy: Object created by the AOP framework.AOP TERMINOLOGY Target object: Object containing the joinpoint. Also referred to as advised or proxied object. including advice.

and then invokes the target method. performs additional aspect logic. The proxy handles method calls.SPRING AOP Spring aspects are implemented as proxies that wrap the target object. Venkat Krishnan 20/11/2012 .

springframework.aop.aop.MethodInterceptor Before advice: org.springframework.aop.SPRING ADVICES Different advice types include: Around advice: org.MethodBeforeAdvice After throwing advice: org.AfterReturningAdvice Venkat Krishnan 20/11/2012 .aopalliance.ThrowsAdvice After returning advice: org.intercept.springframework.

Spring uses the term advisor for an object representing an aspect. Venkat Krishnan 20/11/2012 . including both an advice and a pointcut targeting it to specific joinpoints.CONCEPT Spring provides classes to represent pointcuts and different advice types.

Venkat Krishnan 20/11/2012 .