File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed
src/main/java/com/baeldung/annotations Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 89
89
<scope >provided</scope >
90
90
</dependency >
91
91
92
+ <!-- AOP -->
93
+ <dependency >
94
+ <groupId >org.aspectj</groupId >
95
+ <artifactId >aspectjrt</artifactId >
96
+ <version >1.9.1</version >
97
+ </dependency >
98
+ <dependency >
99
+ <groupId >org.aspectj</groupId >
100
+ <artifactId >aspectjweaver</artifactId >
101
+ <version >1.9.1</version >
102
+ </dependency >
103
+
92
104
</dependencies >
93
105
94
106
<build >
Original file line number Diff line number Diff line change
1
+ package com .baeldung .annotations ;
2
+
3
+ import org .aspectj .lang .ProceedingJoinPoint ;
4
+ import org .aspectj .lang .annotation .Around ;
5
+ import org .aspectj .lang .annotation .Aspect ;
6
+ import org .aspectj .lang .annotation .Pointcut ;
7
+ import org .springframework .stereotype .Component ;
8
+
9
+ import java .util .concurrent .TimeUnit ;
10
+ import java .util .logging .Logger ;
11
+
12
+ @ Aspect
13
+ @ Component
14
+ public class PerformanceAspect {
15
+
16
+ private static Logger logger = Logger .getLogger (PerformanceAspect .class .getName ());
17
+
18
+ @ Pointcut ("within(@org.springframework.stereotype.Repository *)" )
19
+ public void repositoryClassMethods () {
20
+ }
21
+
22
+ @ Around ("repositoryClassMethods()" )
23
+ public Object measureMethodExecutionTime (ProceedingJoinPoint pjp ) throws Throwable {
24
+ long start = System .nanoTime ();
25
+ Object retval = pjp .proceed ();
26
+ long end = System .nanoTime ();
27
+ String methodName = pjp .getSignature ().getName ();
28
+ logger .info ("Execution of " + methodName + " took " + TimeUnit .NANOSECONDS .toMillis (end - start ) + " ms" );
29
+ return retval ;
30
+ }
31
+
32
+ }
You can’t perform that action at this time.
0 commit comments