拦截器代码
package com.learning.springcloud.order.feign;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import java.util.UUID;
public class CustomFeignInterceptor implements RequestInterceptor {
@Override
public void apply(RequestTemplate requestTemplate) {
// eg: 统一自定义请求信息信息
String customHeaderInfo = UUID.randomUUID().toString();
requestTemplate.header("custom_header_info", customHeaderInfo);
}
}
拦截器配置
配置类
package com.learning.springcloud.order.feign.config;
import com.learning.springcloud.order.feign.FeignAuthRequestInterceptor;
import feign.Logger;
import feign.Request;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @Configuration 作用域为所有的服务提供方 全局配置
* 局部配置: FeignClient configuration的值
*/
@Configuration
public c