The final kind of advice is around advice. Around advice runs “around” a matched method execution. It is declared using @Around annotation.
For sample code in details, refer the following link. Click Here
1. Aspect Class
Now write a Aspect which will profile our business method.
BusinessAspect.java
package com.kruders.spring.aspect;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
@Aspect
public class BusinessAspect {
@Pointcut("execution(* com.kruders.spring.aop.BusinessImpl*.*(..))")
public void businessMethods() { }
@Around("businessMethods()")
public void around(ProceedingJoinPoint joinPoint) throws Throwable {
System.out.println("Around method is called");
System.out.println("Around before is running");
joinPoint.proceed();
System.out.println("Around after is running");
}
}
joinPoint.proceed(); controls when should the interceptor return the control to the original doSomeThing() method.
2. 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.