新增配置
package com.zhy.viewer.config; import feign.RequestInterceptor; import feign.RequestTemplate; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Configuration; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; import javax.servlet.http.HttpServletRequest; import java.util.Enumeration; import java.util.Objects; /** * feign转发header * * @author zhy */ @Configuration @Slf4j public class FeignConfiguration implements RequestInterceptor { @Override public void apply(RequestTemplate template) { ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder .getRequestAttributes(); HttpServletRequest request = Objects.requireNonNull(attributes).getRequest(); Enumeration<String> headerNames = request.getHeaderNames(); if (headerNames != null) { while (headerNames.hasMoreElements()) { String name = headerNames.nextElement(); String values = request.getHeader(name); template.header(name, values); } log.info("feign interceptor header:{}", template); } } }调用的地方
@FeignClient(name = "zhy-ai", configuration = FeignConfiguration.class) public interface CtFeignClientService { /** * 提交 */ @PostMapping(value = "/zhy/api/submit") void viewerSubmitAlgorithm(@RequestBody ViewerDto viewerDto); }