【问题标题】:How to list REST API calls made to server [duplicate]如何列出对服务器进行的 REST API 调用 [重复]
【发布时间】:2019-08-12 07:07:37
【问题描述】:

我有一个 Spring Boot 后端应用程序,我想列出客户端对我的应用程序进行的所有 REST API 调用。 我在 Tomcat/nginx 中运行我的应用程序。

【问题讨论】:

标签: rest api spring-boot tomcat catalina


【解决方案1】:

方式 1(执行器): 您可以使用 Spring Boot Actuator 跟踪最后 100 个请求。这是执行此操作的方法:

添加maven依赖

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>

编辑 application.properties 并添加以下行:

management.endpoints.web.exposure.include=* 

运行你的 spring boot 应用程序后,现在你可以通过调用这个 url 来跟踪最近的 100 个 http 请求: http://localhost:8070/actuator/httptrace

方式 2(方面):

但您也可以使用 Aspect 获取日志。

它为您提供了一些令人惊叹的注释,例如:@Before、@AfterReturning、@AfterThrowing 等。

这里@Before记录url,请求参数@AfterReturning记录响应参数,@AfterThrowing记录错误信息,你可能不需要所有端点记录,所以这里有一些基于包的过滤器。

要使用方面检查this anawer来实现此功能

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-26
    • 2013-12-15
    • 1970-01-01
    • 2012-12-22
    • 1970-01-01
    • 2016-01-21
    • 1970-01-01
    相关资源
    最近更新 更多