AOP가 필요한 상황

진성대·2023년 9월 17일
0

java spring

목록 보기
11/15

AOP(Aspect Oriented Programming)가 필요한 상황

  • 공통인 로직을, 관리하기 편하게 하기 위해서 공통 관심 사항(cross-cutting concern) vs 핵심 관심 사항(core concern)분리

스프링의 AOP 동작 방식 설명

@Aspect
@Component
public class TimeTraceAop {

	@Around("execution(* hello.hellospring..*(..))")
    public Object execute(ProceedingJoingPoint jointPoint) 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 적용 후 의존 관계
helloController -> 프록시(memberService)(cglib) -joinPoint.proceed()-> 실제(memberService)

profile
신입 개발자

0개의 댓글