当服务接受http请求时,我想在MDC中放入“ UUID”。 因为它方便了日志搜索。
我继承了HttpRequestHandlingMessagingGateway并发现handleRequest()是最终的,因此我无法覆盖它。
那么当接受请求(MDC.put())并编写响应(MDC.remove())时,有什么办法做吗?
答案 0 :(得分:0)
好吧,以这种方式处理请求不是HttpRequestHandlingMessagingGateway
的责任。
我认为您需要查看 Web过滤器注册:https://www.mkyong.com/spring-mvc/how-to-register-a-servlet-filter-in-spring-mvc/
从概念上讲,您可以借用现有的AbstractRequestLoggingFilter
:
* Base class for {@code Filter}s that perform logging operations before and after a request
* is processed.
*
* <p>Subclasses should override the {@code beforeRequest(HttpServletRequest, String)} and
* {@code afterRequest(HttpServletRequest, String)} methods to perform the actual logging
* around the request.