https://blog.csdn.net/wo18237095579/article/details/83343915
注意,启动类上加上
调用的和被调用的都要加
@EnableEurekaClient
@EnableFeignClients
@EnableEurekaClient
@EnableFeignClients
public class ResServerApplication {
public static void main(String[] args){
SpringApplication.run(ResServerApplication.class);
}
}
然后直接创建一个FeignConfig
@Configuration
public class FeignConfig implements RequestInterceptor {
@Override
public void apply(RequestTemplate requestTemplate) {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
requestTemplate.header(HttpHeaders.AUTHORIZATION, request.getHeader(HttpHeaders.AUTHORIZATION));
}
}
然后在@FeginClient注解上加一个属性
@FeignClient(name = "自己服务的名称",configuration ={FeignConfig.class})
重启调用就ok了