Feign Conifguration配置

Posted 500年

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Feign Conifguration配置相关的知识,希望对你有一定的参考价值。

Feign Conifguration配置

package com.webber.cm.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.support.SpringEncoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.ObjectFactory;

@Configuration
public class MyFeignConfiguration implements RequestInterceptor {
	
    @Autowired
    private ObjectFactory<HttpMessageConverters> messageConverters;

    @Bean
    public Encoder feignFormEncoder() {
        return new SpringFormEncoder(new SpringEncoder(messageConverters));
    }
    
    @Override
    public void apply(RequestTemplate template) {
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder
                .getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        String referer = request.getHeader("referer");
        String cookie = request.getHeader("cookie");
        template.header("referer",referer);
        template.header("cookie",cookie);
    }
 }

以上是关于Feign Conifguration配置的主要内容,如果未能解决你的问题,请参考以下文章

SpringCloud http客户端Feign -- 自定义Feign的配置(一般情况下需要配置的是日志级别)Feign的配置优化

SpringCloud系列六:Feign接口转换调用服务(Feign 基本使用Feign 相关配置)

微服务5声明式 HTTP 客户端 —— Feign

Feign远程调用

SpringCloud+Feign环境下文件上传与form-data同时存在的解决办法

SpringBoot b2b2c 多用户商城系统-docker-feign配置