AOP란
Aspect Oriented Programming 으로 관점 지향 프로그래밍이다. 어떤 로직을 기준으로 핵심적인 관점과 부가적인 괌점으로 나누어서 보고 그 관점을 기준으로 각각 모듈화하겠다는 것을 말한다.

위와 같이 흩어져있는 관심사를 Aspect로 모듈화하고 핵심적인 비즈니스 로직에서 분리하여 재사용하는 것이 AOP의 취지이다.
AOP 적용
package hello.hello_spring.aop;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
@Component
@Aspect
public class TimeTraceAop {
@Around("execution(* hello.hello_spring..*(..))")
public Object execute(ProceedingJoinPoint joinPoint) throws Throwable {
long start = System.currentTimeMillis();
System.out.println("START: " + joinPoint.toString());
try {
return joinPoint.proceed();
} finally {
long finish = System.currentTimeMillis();
long timsMs = finish - start;
System.out.println("END: " + joinPoint.toString() + " " + timsMs + "ms" );
}
}
}
@Component 와 @Aspect 어노테이션을 추가한다.
실제 동작 방식

'Spring' 카테고리의 다른 글
| [Spring] 회원 도메인 (0) | 2025.10.22 |
|---|---|
| [Spring] 객체 지향 프로그래밍 (0) | 2025.10.18 |
| [Spring] JPA (0) | 2025.10.01 |
| [Spring] 스프링 통합테스트 / JdbcTemplate (0) | 2025.09.29 |
| [Spring] 스프링 DB 접근 기술 (0) | 2025.09.28 |