1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
@Component public class FeignRequestInterceptor implements RequestInterceptor { @Override public void apply(RequestTemplate requestTemplate) { ServletRequestAttributes attributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes(); if(attributes != null) { HttpServletRequest request = attributes.getRequest(); String token = request.getHeader(HttpHeaders.AUTHORIZATION); if(StringUtils.isNotEmpty(token)) { requestTemplate.header(HttpHeaders.AUTHORIZATION, token); } } } }
|