
의존성추가
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
Advice와 Pointcut 정의 (기존의 Proxy 클래스 제거)
@Component
@Aspect
public class PerfAspect {
    @Around("execution(* me.choi..*.EventService.*(..))")
    public Object lofPerf(ProceedingJoinPoint pjp) throws Throwable {
        long begin = System.currentTimeMillis();
        Object retVal = pjp.proceed();
        System.out.println(System.currentTimeMillis()-begin);
        return retVal;
    }
}@Aspect : 해당 클래스가 Aspect 임을 정의 (Aspect: 하나의 모듈)
해야할 일(Advice), 해야할 일을 어디에 적용할 것인가(PointCut)?
ProceedingJoinPoint : Advice가 적용이 되는 대상
@Around("PointCut이름 or PointCut 직접 정의") : 해당 Advice를 어떻게 적용할 것인가를 정의

execution 명시자
- Advice를 적용할 메서드 지정
- 기본 형식 :
-> "*" 는 모든 값을 의미
-> ".." 는 0개 이상 의미
| execution([수식어] [리턴타입] [클래스이름] [이름]([파라미터]) | 
출처: https://groovysunday.tistory.com/201 [성냥의 불친절한 IT 이야기]
스프링(Spring) AOP : AspectJ Pointcut 표현식 (1-1) execution
execution 명시자 - Advice를 적용할 메서드 지정 - 기본 형식 : -> "*" 는 모든 값을 의미 -> ".." 는 0개 이상 의미 execution([수식어] [리턴타입] [클래스이름] [이름]([파라미터]) 수식어 - 생략가능 - publi..
groovysunday.tistory.com
문제점

위와 같이 Delete는 성능을 측정하고 싶지 않았지만 나와버렸다...
Annotation 적용
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface PerfLogging {
}

이전 @Around(excution) 말고 만들었던 애노테이션을 적용하자
@Component
@Aspect
public class PerfAspect {
    //@Around("execution(* me.choi..*.EventService.*(..))")
    @Around("@annotation(PerfLogging)")
    public Object lofPerf(ProceedingJoinPoint pjp) throws Throwable {
        long begin = System.currentTimeMillis();
        Object retVal = pjp.proceed();
        System.out.println(System.currentTimeMillis()-begin);
        return retVal;
    }
}결과

기타 방법 (@Before, @Around(bean("")))
    @Around("bean(simpleEventService)")
    public Object lofPerf(ProceedingJoinPoint pjp) throws Throwable {
        long begin = System.currentTimeMillis();
        Object retVal = pjp.proceed();
        System.out.println(System.currentTimeMillis()-begin);
        return retVal;
    }
    @Before("bean(simpleEventService)")
    public void hello(){
        System.out.println("hello!!");
    }@Around를 위의 애노테이션 말고 bean으로 설정할수있다.
-> 하지만 해당 빈의 모든 메서드에 적용된다는 점에 유의하자!
@Before를 사용하면
해당 빈이 사용되기 이전에 실행되게끔 도와준다.
코드참고
https://github.com/mike6321/Spring/tree/master/Spring/AOP
mike6321/Spring
Contribute to mike6321/Spring development by creating an account on GitHub.
github.com
'Spring > Spring' 카테고리의 다른 글
| (SPRING) IoC 컨테이너 - ApplicationContext와다양한 빈 설정 방법 (0) | 2020.01.01 | 
|---|---|
| (SPRING) IoC 컨테이너 - 스프링 IoC 컨테이너와 빈 (0) | 2019.12.31 | 
| (SPRING) 스프링 AOP : 프록시 기반 AOP (0) | 2019.12.25 | 
| (SPRING) 스프링 웹 애플리케이션 제거방법 (0) | 2019.12.25 | 
| (SPRING) AOP(Aspect-Oriented-Programming) (0) | 2019.12.24 | 
 
										
									 
										
									 
										
									