java—在spring中测量请求所需的时间

dsekswqp  于 2021-08-25  发布在  Java
关注(0)|答案(0)|浏览(215)

如何创建一个自定义注解来测量完成请求所需的时间?
其思想是使用自定义注解来注解@restcontroller方法,如 @RequestPerformanceAnnotation ,但我不会更进一步。
这就是我到目前为止所做的:

public class RequestPerformance {

    @RequestPerformanceAnnotation
    public static void main(String[] args) throws Exception {
        new RequestPerformance().timer();
    }

    public void timer() {
        System.out.println("*****TIMER*****");

        // Make it availiable for all classed that extends this one
        Class<? extends RequestPerformance> obj = this.getClass();

        // Process @RequestPerformanceAnnotation
        for (Method method : obj.getDeclaredMethods()) {

            if (method.isAnnotationPresent(RequestPerformanceAnnotation.class)) {
                Annotation annotation = obj.getAnnotation(RequestPerformanceAnnotation.class);
                RequestPerformanceAnnotation reqPerfAnnotation = (RequestPerformanceAnnotation) annotation;

                System.out.println("*****HERE*****");
                System.out.println("*****HERE*****");
                System.out.println("*****HERE*****");
                System.out.println("*****HERE*****");
                System.out.println("*****THERE*****");
            }
        }
    }
}

我能够将数据打印到这个类的控制台上,但是我不能在@restcontroller方法中这样做。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题