Last active
October 28, 2018 03:30
-
-
Save LeoHeo/db1a6cc9a0106f3a099cd2d494c1b904 to your computer and use it in GitHub Desktop.
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
@Documented | |
@Retention(RetentionPolicy.CLASS) // default CLASS -> SOURCE, RUNTIME으로 변경할 필요 없음 | |
@Target(ElementType.METHOD) | |
public @interface PerformaceLogging { | |
} |
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
@Component | |
@Aspect | |
public class PerformanceAspect { | |
@Around("@annotation(PerformaceLogging)") // bean으로 설정하는 방법도 있다. | |
public Object logPeformace(ProceedingJoinPoint pjp) throws Throwable { | |
long begin = System.currentTimeMills(); | |
Object returnProceed = pjp.proceed(); | |
System.out.println((System.currentTimeMillis() - begin)); | |
return returnProceed; | |
} | |
} |
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
@Service | |
public class TestService { | |
@PerformaceLogging // 필요한 method에 annotation을 달아준다. | |
public String test2() { | |
try { | |
Thread.sleep(2); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
return "test"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment