Last active
August 11, 2020 09:33
-
-
Save neo7BF/adb51a4f75973a1fd6b3a1914d3b4dc9 to your computer and use it in GitHub Desktop.
Misuring execution time of queries with spring aop and spring jdbc in spring boot
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 | |
@Slf4j | |
public class LoggingExecutionTimeQueryAspect { | |
//replace <> with your own repository class info for tracing execution time of queries of that Repository | |
private Temporal startTime; | |
@Before("execution(* <PACKAGE>.<RESPOSITORY_CLASS_NAME>.*(..))") | |
public void logBeforeQueryInvocation(JoinPoint joinPoint){ | |
startTime = Instant.now(); | |
} | |
@After("execution(* <PACKAGE>.<RESPOSITORY_CLASS_NAME>.*(..))") | |
public void logAfterQueryInvocation(JoinPoint joinPoint){ | |
Duration d = Duration.between(startTime, Instant.now()); | |
log.info("Execution time: " + DurationFormatUtils.formatDurationHMS(d.toMillis()) + " Method: " + joinPoint.getSignature()); | |
} | |
} |
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
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-aop</artifactId> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-data-jdbc</artifactId> | |
</dependency> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment