I have a Spring Boot backend application and I'd like to list all the REST API calls made by clients to my application. I'm running my app in Tomcat/nginx.
-
From list you mean log, right? [check this](https://stackoverflow.com/questions/33744875/spring-boot-how-to-log-all-requests-and-responses-with-exceptions-in-single-pl) – Nikolay Hristov Mar 21 '19 at 12:19
-
1Check this answer. It has complete code: https://stackoverflow.com/a/52164562/3073945 – Md. Sajedul Karim Mar 21 '19 at 12:21
-
@NikolayHristov yes thanks for the correction! – Alexander Phoenix Mar 21 '19 at 12:25
-
@Md.SajedulKarim Thank you!! – Alexander Phoenix Mar 21 '19 at 12:25
1 Answers
Way 1 (Actuator): You can track last 100 request using Spring Boot Actuator. Here is the way to do this :
Add the maven dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Edit the application.properties and add the following line:
management.endpoints.web.exposure.include=*
After running your spring boot application, now you can track the latest 100 http requests by calling this url: http://localhost:8070/actuator/httptrace
Way 2 (Aspect):
But you can also get the log using Aspect.
It provide you some amazing annotation like: @Before , @AfterReturning, @AfterThrowing etc.
Here @Before
log the url,request parameters, @AfterReturning
log the response parameters and @AfterThrowing
log the error with message, You may not don't need all endpoints log, so here have some filters based on package.
To implement this feature using aspects check this anawer

- 6,749
- 3
- 61
- 87