This module contains articles about administering a Spring Boot runtime
- Shutdown a Spring Boot Application
- Programmatically Restarting a Spring Boot Application
- Logging HTTP Requests with Spring Boot Actuator HTTP Tracing
- Spring Boot Embedded Tomcat Logs
- Project Configuration with Spring
- Spring – Log Incoming Requests
- How to Configure Spring Boot Tomcat
感想:
-
要实现在请求中记录时间的需求,可以通过HandlerInterceptorAdapter继承的办法, 在preHandle记录开始时间,在afterCompletion记录结束的时间,前后两个时间相减得到运行时间。另一种设置记录时间的方法是用threadlocal往request里设置字段的办法。
-
原文中先使用Interceptor,然后使用filter, 这样做的原因是对于非x-www-form-urlencoded的post请求体, 只能用getInputStream()获取流的具体内容。这里有个问题,而getInputStream()输入请求的流只能读取一次。 如果想实现流的多次读取, 就要把流写回去,就只能用到filter了,在这里用的是springboot提供的CommonsRequestLoggingFilter (通用请求日志过滤器)。