配置类

  1. @Configuration
  2. public class FeignConfiguration implements RequestInterceptor {
  3. private final Logger logger = LoggerFactory.getLogger(getClass());
  4. @Override
  5. public void apply(RequestTemplate template) {
  6. ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder
  7. .getRequestAttributes();
  8. HttpServletRequest request = attributes.getRequest();
  9. Enumeration<String> headerNames = request.getHeaderNames();
  10. if (headerNames != null) {
  11. while (headerNames.hasMoreElements()) {
  12. String name = headerNames.nextElement();
  13. String values = request.getHeader(name);
  14. template.header(name, values);
  15. }
  16. logger.info("feign interceptor header:{}", template);
  17. }
  18. }
  19. }

使用方式

  1. @FeignClient(value = "", configuration = FeignConfiguration.class)