본문 바로가기

나혼자개발

[spring] AOP예시코드

package project.developmentstudy.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect  //aop를 쓰기위한 어노테이션
@Component  //빈등록
public class TimeTraceAop {

    @Around("execution(* project.developmentstudy..*(..))")
    public Object excute(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");
        }
    }
}

'나혼자개발' 카테고리의 다른 글

thymeleaf 사용법  (1) 2024.10.25
만들예정 화면  (0) 2024.07.11
SpringSecurity 사용방법  (0) 2024.07.09
ResponseDto에 들어갈 코드  (0) 2024.07.08
javascript+jquery로 데이터보낼때 예시  (0) 2024.07.08