Share on Google+Share on Google+

Spring AOP Around Advice

In this tutorial you will learn about Spring AOP Around Advice and its mapping in XML file.

Spring AOP Around Advice

Around Advice performs the custom behavior before and after method invocation by surrounding a join point. It is called before and After method execution when you need advice for both entry and exit then only use this advice. To implement around advice you need to implement MethodInterceptor of import org.aopalliance.intercept.MethodInterceptor package.


public interface SimpleInterface {
	void testMethod();


public class SimpleInterfaceImpl implements SimpleInterface {
	public void testMethod() {
		System.out.println(" This is Test Method();");


import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

public class AroundAdviceExample implements MethodInterceptor {
	public Object invoke(MethodInvocation method) throws Throwable {
		System.out.println(" Advice Before method");
		Object obj = method.proceed();
		System.out.println("Advice After Method");
		return null;



import org.springframework.context.ApplicationContext;

public class AroundAdviceTest {
	public static void main(String[] args) {

		ApplicationContext applicationContext = new FileSystemXmlApplicationContext(

		SimpleInterface simpleInterface = (SimpleInterface) applicationContext



<?xml version="1.0" encoding="UTF-8"?>


    <!-- Bean configuration -->
    <bean id="proxyBean"
        <property name="proxyInterfaces">
        <property name="target">
            <ref local="beanTarget" />
        <property name="interceptorNames">

    <!-- Bean Classes -->
    <bean id="beanTarget" class="" />

    <!-- Advisor pointcut definition for before advice -->
    <bean id="theTracingAroundAdvisor"
        <property name="advice">
            <ref local="theTracingAroundAdvice" />
        <property name="pattern">

    <!-- Advice classes -->
    <bean id="theTracingAroundAdvice"
        class="" />


When you run this application it will display message as shown below:

Advice Before method
This is Test Method();
Advice After Method

Download this example code


Posted on: September 3, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.


Advertisement null