Java tutorial
/* * Copyright (c) 2014, lingang.chen@gmail.com All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); */ package ${package}.core.shared.aspect; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.AfterThrowing; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import ${package}.common.shared.annotation.AspectLogger; /** * Reason: . * * @author chenlg * @version $Id: CoreAspect.java, v 0.1 2014224 ?4:23:02 chenlg Exp $ * @since JDK 1.7 * @see */ @Component @Aspect public class CoreAspect { private static Logger logger = LoggerFactory.getLogger("CMMI_CORE_DIGEST"); /** * */ @Pointcut("execution(* ${package}.core..*.*(..)) ") public void corePointcut() { // pointcut?Annotation?pointcut } /** * . * * @param jionpoint * @param e */ @AfterThrowing(pointcut = "corePointcut() && @annotation(aspectLogger)", throwing = "e") public void throwingAdvice(JoinPoint jionpoint, AspectLogger aspectLogger, Exception e) { /* * ???. */ String targetClassName = jionpoint.getTarget().getClass().getName(); /* * ???. */ String targetMethodName = jionpoint.getSignature().getName(); /* * ??. */ String desc = aspectLogger.value(); /* * ?. */ StringBuilder aspectMessage = new StringBuilder(); aspectMessage.append("[]:(").append(desc).append("),(").append(targetClassName) .append(".").append(targetMethodName).append(")").append(",?()"); /* * . */ logger.info(aspectMessage.toString()); } /** * . * * @param jionpoint * @return * @throws Throwable */ @Around("corePointcut() && @annotation(aspectLogger)") public Object aroundAdvice(ProceedingJoinPoint jionpoint, AspectLogger aspectLogger) throws Throwable { /* * . */ long l1 = System.currentTimeMillis(); /* * ??. */ String desc = aspectLogger.value(); /* * ???. */ String targetMethodName = jionpoint.getSignature().getName(); /* * ???. */ String targetClassName = jionpoint.getTarget().getClass().getName(); /* * ?. */ Object o = jionpoint.proceed(); /* * ?. */ long l2 = System.currentTimeMillis(); /* * ?. */ StringBuilder aspectMessage = new StringBuilder(); aspectMessage.append("[]:(").append(desc).append("),(").append(targetClassName) .append(".").append(targetMethodName).append("),(").append(l2 - l1).append("ms)") .append(",?()"); /* * . */ logger.info(aspectMessage.toString()); //Object o = jionpoint.proceed();//??? return o; } }