我正在尝试为使用 @Timed 注释的每个方法调用 AOP 方法。
我的 AOP MyTracer.java
@Aspect
public class MyTracer {
private static final Tracer tracer = Tracing.getTracer();
private static final Logger log = Logger.getLogger(MyTracer.class.getName());
@Around("@annotation(timed)")
public Object trackExecutionTime(ProceedingJoinPoint proceedingJoinPoint, Timed timed) throws Throwable {
String methodName = proceedingJoinPoint.getSignature().getName();
log.info("Using AOP for method name" + methodName);
log.info("Using AOP for param name" + timed.label());
return output;
}
}
}
我的注释
定时.java
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Timed {
String label() default "label";
}
最后是我的业务代码
HelloWorld.java
@Override
@Timed(label = "myMetrics")
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
log.info("Servlet called");
PrintWriter out = resp.getWriter();
out.println("Hello, world - Flex Servlet");
}
在运行时,我从 servlet 但不是 MyTracer 类获取日志。