一种选择是使用ServletFilter:
public class UniqueRequestFilter implements Filter { public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { String requestID = UUID.randomUUID().toString() //save to ThreadLocal... try { chain.doFilter(req, res); } finally { //remove from ThreadLocal } } public void init(FilterConfig config) throws ServletException { } public void destroy() { }}您可以随时在应用程序中从ThreadLocal获取请求值。



