Created
April 8, 2019 02:35
-
-
Save moods445/ffee863ea92112c8efdf172e82ddec54 to your computer and use it in GitHub Desktop.
AOP #spring #java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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