[스프링 입문] AOP

JYC·2024년 1월 4일

[SPRING STUDY]

목록 보기
8/39

AOP가 필요한 상황

  • 모든 메소드의 호출 시간을 측정할 때
  • 회원 가입 시간, 회원 조회 시간을 측정할 때
  • 공통 관심 사항 VS 핵심 관심 사항 분리할 때

시간 측정 AOP

@Aspect
@Component
public class TimeTraceAop {
    @Around("execution(* hello.hellospring..*(..))")
    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 timeMs = finish-start;
            System.out.println("END: "+joinPoint.toString()+" "+timeMs+"ms");
        }
    }
}

AOP 적용 전

AOP 적용 후


스프링의 AOP 동작 방식 설명

AOP 적용 전

AOP 적용 후


profile
열심히 하기 1일차

0개의 댓글