12306 网站开发,网站seo优化主要有哪些手段,直播营销,专门做网站需要敲代码么FeignClient 的 configuration 属性#xff1a;
Feign 注解 FeignClient 的 configuration 属性#xff0c;可以对 feign 的请求进行配置。
包括配置Feign的Encoder、Decoder、 Interceptor 等。
feign 请求添加拦截器#xff0c;也可以通过这个 configuration 属性 来指…FeignClient 的 configuration 属性
Feign 注解 FeignClient 的 configuration 属性可以对 feign 的请求进行配置。
包括配置Feign的Encoder、Decoder、 Interceptor 等。
feign 请求添加拦截器也可以通过这个 configuration 属性 来指定。
feign 请求拦截器 RequestInterceptor
feign 的拦截器需要实现 RequestInterceptor 接口重写 apply() 方法。
apply() 方法参数为 RequestTemplate。
RequestTemplate 获取 url : //url 的路径为 被调用的服务路径比如 b-service/user/infoString url requestTemplate.url();RequestTemplate 获取body 参数 byte[] bodyBytes requestTemplate.body();if (bodyBytes ! null) {JSONObject bodyJson (JSONObject) JSON.toJSON(bodyBytes);}
增加 header 参数 requestTemplate.header(xxx, kkk);示例
FeignInterceptorConfigDemo 配置类
Configuration
public class FeignInterceptorConfigDemo {/*** feign 拦截器* return*/Beanpublic RequestInterceptor requestInterceptor() {return new MyRequestInterceptor();}/*** 实现拦截器RequestInterceptor*/static class MyRequestInterceptor implements RequestInterceptor {Overridepublic void apply(RequestTemplate template) {//示例添加 headertemplate.header(Content-Type, application/json;charsetutf-8);//url 的路径为 被调用的服务路径比如 b-service/user/infoString url template.url();//示例获取body 参数byte[] bodyBytes template.body();if (bodyBytes ! null) {JSONObject bodyJson (JSONObject) JSON.toJSON(bodyBytes);System.out.println(body参数 bodyJson);}//示例针对特殊的 url 进行处理if (url.contains(verifyResult)) {//处理逻辑。比如增加 header 参数、 针对特定属性进行拦截等等。template.header(userIdTest, abcde);}}}}
FeignClient 注解 指定 拦截器配置
在 configuration 属性中指定配置为 以上设置的 FeignInterceptorConfigDemo 即可添加拦截器。
FeignClient(name myService, configuration FeignInterceptorConfigDemo.class)
RequestMapping(/myService)
public interface MyFeignService {}