import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; @Aspect public class PerformanceAspect { @Around("execution(* com.example.library.*.*(..))") public Object measurePerformance(ProceedingJoinPoint joinPoint) throws Throwable { long startTime = System.currentTimeMillis(); Object result = joinPoint.proceed(); long endTime = System.currentTimeMillis(); System.out.println("Method " + joinPoint.getSignature().getName() + " executed in " + (endTime - startTime) + " ms"); return result; } } <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>aspectj-maven-plugin</artifactId> <version>1.11</version> <executions> <execution> <goals> <goal>compile</goal> </goals> <configuration> <source>1.8</source> <target>1.8</target> <aspectLibraries> <aspectLibrary> <groupId>com.example</groupId> <artifactId>aspect-library</artifactId> </aspectLibrary> </aspectLibraries> </configuration> </execution> </executions> </plugin> </plugins> </build>


上一篇:
下一篇:
切换中文