Skip to content

Instantly share code, notes, and snippets.

@moods445
Created April 8, 2019 02:35
Show Gist options
  • Save moods445/ffee863ea92112c8efdf172e82ddec54 to your computer and use it in GitHub Desktop.
Save moods445/ffee863ea92112c8efdf172e82ddec54 to your computer and use it in GitHub Desktop.

Revisions

  1. moods445 created this gist Apr 8, 2019.
    30 changes: 30 additions & 0 deletions AopSample.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@

    import org.aspectj.lang.ProceedingJoinPoint;
    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.context.annotation.Profile;
    import org.springframework.stereotype.Component;

    @Aspect
    public class AopSample{
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Pointcut("exection()")
    public void executeTime() {
    }

    @Around("executeTime()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
    long startTime = System.currentTimeMillis();
    try {
    return joinPoint.proceed();
    } finally {
    long timeTaken = System.currentTimeMillis() - startTime;
    logger.info("Time Taken({} ms) by {}", timeTaken, joinPoint);
    }
    }

    }