ruijiege

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
package com.fxtech.config;

import com.fxtech.base.filter.ShopFilter;
import feign.RequestInterceptor;
import feign.RequestTemplate;
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;

@Configuration
public class FeignConfiguration implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate template) {
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder
                .getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        Enumeration<String> headerNames = request.getHeaderNames();
        if (headerNames != null) {
            while (headerNames.hasMoreElements()) {
                String name = headerNames.nextElement();
                String values = request.getHeader(name);
                template.header(ShopFilter.INNER_TOKEN, ShopFilter.INNER_TOKEN_VALUE);

            }
        }
    }
}

 复写这个拦截器然后添加header,然后在fegin中添加

@FeignClient(value = "${remote.feign.salesOrder.name}",configuration = FeignConfiguration.class)

 

posted on 2021-01-28 10:53  哦哟这个怎么搞  阅读(171)  评论(0编辑  收藏  举报