I want to put a "UUID" into MDC when the service accept a http request. Because it's convenience for log search.
I was inherited HttpRequestHandlingMessagingGateway and found the handleRequest() was final so that I can't overwrite it .
So is there a way to do something when accept a request(MDC.put()) and write response(MDC.remove()) ?
Well, this is not an HttpRequestHandlingMessagingGateway
responsibility to manipulate a request that way.
I think you need to take a look into a Web Filter registration: https://www.mkyong.com/spring-mvc/how-to-register-a-servlet-filter-in-spring-mvc/
As a point of idea you can borrow an existing 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.