AOPの適用


  • AOP : Aspect Oriented Programming
  • 共通の注目点とコアの注目点を分離
  • TimeTraceAop.java
    @Aspect
    @Component
    public class TimeTraceAop {
        @Around("execution(* com.hello.hellospring..*(..))")
        public Object execute(ProceedingJoinPoint joinPoint) throws Throwable {
            long start = System.currentTimeMillis();
            System.out.println("START: " + joinPoint.toString());
            try {
                Object result = joinPoint.proceed();
                return result;
            }finally {
                long finish = System.currentTimeMillis();
                long timeMs = finish = start;
                System.out.println("END: " + joinPoint.toString() + " " + timeMs + "ms");
            }
        }
    }
    解決する
  • 会員加入、会員照会などの核心関心事項と測定時間の共通関心事項は
  • に分かれている.
    測定
  • 時間の論理を独立した汎用論理
  • にした.
  • 適用オブジェクト
  • を選択可能

  • は、実際のProxyが注入されているかどうかを確認するためにコンソールに出力することができる