Spring AOP AroundAdvice

In this article you will see how to use around advice of spring aop. The final kind of advice is around advice. Around advice runs “around” a matched method execution.

For sample code in details, refer the following link. Click Here

1. Advice Class

Now write a Advice BusinessAroundMethod.java which will profile our business method.


package com.kruders.spring.advice;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
public class BusinessAroundMethod implements MethodInterceptor{
    public Object invoke(MethodInvocation method) throws Throwable {
        System.out.println("Around method is called");
        System.out.println("Around before is running");
        System.out.println("Around after is running");
        return null;

2. Configure Spring AOP

Create Spring-Business.xml and write the following code


<bean id="businessService" class="com.kruders.spring.aop.BusinessImpl" />
    <!-- Advice -->
    <bean id="businessAdvice" class="com.kruders.spring.advice.BusinessAroundMethod" />
    <bean id="businessServiceProxy"
    <property name="target" ref="businessService" />
    <property name="interceptorNames">

3. Output

When you run the above example you’ll get an output like:

Around method is called
Around before is running
Do Something Here
Around after is running

No comments yet.

Leave a Reply