Aspect Oriented Programming
공통관심사항과 핵심관심 사항을 분리(cross-cutting concern, core concern)
모든 클래스에 공통 관심 사항을 적용하기 위해 사용
예: 모든 클래스의 동작 시간을 측정하는 것을 전부 적용하기....
aop 없으면 모든 코드에 동일/반복 코드를 넣어야
@Aspect
@Component
public class TimeTraceAop {
@Around("execution(* com.myvms..*(..))") // com.myvms 패키지의 모든 클래스에 적용
public Object execute(ProceedingJoinPoint joinPoint) throws Throwable{
long start = System.currentTimeMillis();
System.out.println("Start : " + joinPoint.toString());
try {
Object ojb = joinPoint.proceed();
return ojb;
} finally {
long finish = System.currentTimeMillis();
long timeMs = finish - start;
System.out.println("End: " + joinPoint.toString() + " " + timeMs + "ms");
}
}
}
'Spring > spring_old' 카테고리의 다른 글
01. Spring Project 개요 (0) | 2023.01.18 |
---|---|
07./ Spring Web MVC-DB연계-Spring DATA JPA-이름 포함 검색 출력 (0) | 2023.01.15 |
02./ Spring folder 구조 (0) | 2023.01.14 |
07./ Spring Web MVC-DB연계-Spring DATA JPA (0) | 2023.01.14 |
07./ Spring Web MVC-DB연계-JPA (0) | 2023.01.13 |