Spring AOP AfterReturningAdvice

In this article you will see how to use after returing advice of spring aop. After returning advice runs when a matched method execution returns normally.

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

1. Advice Class

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


package com.kruders.spring.advice;
import java.lang.reflect.Method;
import org.springframework.aop.AfterReturningAdvice;
public class BusinessAfterReturning implements AfterReturningAdvice{
    public void afterReturning(Object returnValue, Method method,
            Object[] args, Object target) {
        System.out.println("After method is called (by " + this.getClass().getName() + ")");

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.BusinessAfterReturning" />
    <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:

Do Something Here
After method is called (by com.kruders.spring.advice.BusinessAfterReturning)

No comments yet.

Leave a Reply