Skip to content

Instantly share code, notes, and snippets.

@moods445
Created April 8, 2019 02:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moods445/ffee863ea92112c8efdf172e82ddec54 to your computer and use it in GitHub Desktop.
Save moods445/ffee863ea92112c8efdf172e82ddec54 to your computer and use it in GitHub Desktop.
AOP #spring #java
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);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment