<分区>
我有一个 Spring Boot 后端应用程序,我想列出客户端对我的应用程序进行的所有 REST API 调用。 我在 Tomcat/nginx 中运行我的应用程序。
<分区>
我有一个 Spring Boot 后端应用程序,我想列出客户端对我的应用程序进行的所有 REST API 调用。 我在 Tomcat/nginx 中运行我的应用程序。
最佳答案
方式 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 来实现此功能
关于rest - 如何列出对服务器进行的 REST API 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55280245/