@Component public class UserContextInterceptor implements RequestInterceptor { @Override public void apply(RequestTemplate requestTemplate) { UserContext userContext = UserContextHolder.getUserContext(); requestTemplate.header(UserContext.CORRELATION_ID, userContext.getCorrelationId()); } }
SpringCloud应用中,通过feign的方式实现http的调用,可以通过实现feign.RequestInterceptor接口在feign执行后进行拦截,对请求头等信息进行修改