관점 지향 프로그래밍(Aspect-Oriented Programming)
객체 지향 프로그래밍(OOP)으로 해결하기 어려운 공통 관심 사항(Cross-Cutting Concerns)을 분리하여 관리하는 기법
중복 코드를 줄이고, 핵심 비즈니스 로직과 분리하여 유지보수성을 향상

이렇듯, 관점 지향 프로그래밍에서는 소스코드에서 반복적으로 사용하는 코드를 하나로 묶어서 모듈화하여 재사용성과 유지 보수성을 높일 수 있는 강점을 가지고 있습니다.
로깅(Logging): 메서드 실행 시간 측정, 요청/응답 로깅
트랜잭션 관리(Transaction Management)
보안(Security): 권한 체크
예외 처리(Exception Handling)


위빙은 대상 객체의 생애 중 수행되는 시점에 따라 아래 3가지로 나뉠 수 있다.
Spring에서 AOP는 프록시(Proxy) 패턴을 기반으로 동작
프록시 객체가 실제 객체를 감싸서 부가 기능을 제공
실행 시점(Runtime)에 동적으로 적용 가능
Spring에서는 @Aspect와 @Component를 활용하여 AOP를 구현
@Aspect
@Component
public class LoggingAspect {
@Before("execution(* com.example.service.*.*(..))")
public void beforeMethod(JoinPoint joinPoint) {
System.out.println("[LOG] Method 실행 전: " + joinPoint.getSignature().getName());
}
}

@Around("execution(* com.example.service.*.*(..))")
public Object measureExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
long start = System.currentTimeMillis();
Object result = joinPoint.proceed(); // 실제 메서드 실행
long end = System.currentTimeMillis();
System.out.println("[LOG] " + joinPoint.getSignature().getName() + " 실행 시간: " + (end - start) + "ms");
return result;
}
@Before("execution(* com.example.service.*.*(..))")
*: 반환 타입 무관
com.example.service.*.*(..): service 패키지 내 모든 클래스의 모든 메서드에 적용
@Before("execution(* com.example.service.UserService.getUser(..))")
getUser 메서드 실행 전에 AOP 적용@Around("@annotation(org.springframework.transaction.annotation.Transactional)")
@Transactional이 적용된 메서드에 AOP 적용Spring AOP는 메서드 실행에 대해서만 적용 가능
필드 접근, 생성자 호출 등은 지원하지 않음
AOP를 사용하면 공통 기능을 효율적으로 관리할 수 있음
@Aspect와 다양한 Advice를 활용하여 필요에 맞게 적용 가능
Spring AOP는 프록시 기반이므로 런타임에 동적으로 적용됨
https://adjh54.tistory.com/133
https://velog.io/@youjung/Spring-AOP