Tuesday, June 10, 2014

Spring Aop framework overview

In Spring AOP, 4 type of advices are supported

Before advice – Run before the method execution
After returning advice – Run after the method returns a result
After throwing advice – Run after the method throws an exception
Around advice – Run around the method execution.That is before and after  the method

To implement aop spring uses following interfaces

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.AfterReturningAdvice;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.aop.ThrowsAdvice


MethodInterceptor and MethodInvocation  is present in aoplliance-1.0.jar

Likewise
AfterReturningAdvice,MethodBeforeAdvice,ThrowsAdvice interface is present in org.springframework.aop.jar

That is org.springframework.aop.jar extends interface provided by aoplliance-1.0.jar

Spring aop has extra Advices, Pointcut , Advisor in which in some case
spring extends aoplliance interface
for example
package org.springframework.aop;

import org.aopalliance.aop.Advice;

public abstract interface AfterAdvice extends Advice {
}
In some case it just wrap aop aoplliance interface with extra features

for example
import org.aopalliance.aop.Advice;

public abstract interface Advisor {
public abstract Advice getAdvice();

public abstract boolean isPerInstance();
}
Spring also supports aspectj
Now when used spring with aspectj thease are aspectj annotation

@Before – Run before the method execution
@After – Run after the method returned a result
@AfterReturning – Run after the method returned a result, intercept the returned result as well.
@AfterThrowing – Run after the method throws an exception
@Around – Run around the method execution, combine all three advices above.

So,spring framework creates a new abstraction above aspect j.So,from spring also we can configure aspectj


No comments:

Post a Comment