Aspect with @Around and @Pointcut



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 Passenger {


@Pointcut("execution(** com.Flight.fly(..))")
public void flying() {

}

@Around("flying()")
public void haveJourney(ProceedingJoinPoint jp) {
try {
   System.out.println("Switch of phone");
   System.out.println("Bing seat belt");
   jp.proceed();
   System.out.println("Come out of the Flight!!!");
} catch (Throwable e) {
   System.out.println("Demanding a refund");
}
}
}


@Pointcut
flying() is annotated with @Pointcut, so the flying method become the shortcut for "execution(** com.Flight.fly(..))". and It can be used with @Before, @After, @AfterThrowing
@AfterReturning

In this example flying() is used with the @Around .