목록스프링 5 프로그래밍 입문/7. AOP 프로그래밍 (4)
진취적 삶
org.aspectj aspectjweaver 1.8.13 aspectjweaver 는 AOP를 설정하는데 필요한 애노테이션을 제공한다. package chap07; public interface Calculator { public long factorial(long num); } public class ImpeCalculator implements Calculator{ @Override public long factorial(long num) { long result =1 ; for (long i =1 ; i
실행시간을 출력하려면 메서드의 시작과 끝에서 시간을 구하고 두 시간의 차이를 출력 for 반복문의 경우 public class ImpeCalculator implements Calculator{ @Override public long factorial(long num) { long start = System.currentTimeMillis(); long result =1 ; for (long i =1 ; i
Aspect 로 사용할 클래스에 @Aspect 붙인다 @Pointcut 공통 기능을 적용할 Pointcut을 정의 공통 기능을 구현한 메서드에 @Around 적용 7.3.1 AOP 구현 공통 기능을 제공하는 Aspect 구현 클래스를 만들고 자바 설정을 이용해서 Aspect를 어디에 적용할지 설정 @Aspect public class ExeTimeAspect { @Pointcut("execution(public * chap07..*(..))") private void publicTarget() { } @Around("publicTarget()") public Object measure(ProceedingJoinPoint joinPoint) throws Throwable { long start = Syst..
스프링은 AOP 를 위한 프록시 객체를 생성할 때 실제 생성할 빈 객체가 인터페이스를 상속하면 인터페이스를 이용해서 프록시를 생성한다. RecCalculator 클래스가 calculator 인터페이스를 상속하므로 , calculator 인터페이스를 상속받은 프록시 객체를 생성 인터페이스가 아닌 클래스를 이용해서 프록시를 생성하고 싶다면 @Configuration @EnableAspectJAutoProxy(proxyTargetClass =true) public class AppCtx { 7.4.1 execution 명시자 표현식 @Pointcut("execution(public * chap07..*(..))") private void publicTarget() { } execution 명시자는 Advice..