We are using:
Now we want to use MDC
to add the unique tracking num
Sorry, don't have enough rep to write comment. This is more correct, fully working code, based on @glytching answer:
@Component
public class MDCFilter extends OncePerRequestFilter {
@Autowired
private TrackingnumberGenerator trackGen;
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
MDC.put("trackingNumber", trackGen.getTrackingNumber());
try {
filterChain.doFilter(request, response);
} finally {
MDC.remove("trackingNumber");
}
}
}