JoinPoints in AOP
- It is a specific point in executing a program's code where an aspect can be applied to introduce cross-cutting concerns.
- It is the execution point in the program's flow.
- It is the point where the aspect is executed.
Example:
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class LoggingAspect {
@Before("execution(* com.example.bank.BankService.transferFunds(..))")
public void logBeforeTransfer(JoinPoint joinPoint) {
System.out.println("Before transferring funds...");
}
@After("execution(* com.example.bank.BankService.transferFunds(..))")
public void logAfterTransfer(JoinPoint joinPoint) {
System.out.println("After transferring funds...");
}
}
package com.example.bank;
import org.springframework.stereotype.Service;
@Service
public class BankService {
public void transferFunds(double amount, String fromAccount, String toAccount) {
System.out.println("Transferring $" + amount + " from " + fromAccount + " to " + toAccount);
}
}
Output:
Before transferring funds...
Transferring $100.0 from SavingsAccount to CheckingAccount
After transferring funds...