OpenFeign服务端发送请求携带Token

package cn.woniu.yyyservice.nacosconfig;

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;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: hui
 * @Date: 2021/12/05/17:33
 * @Description:
 */
@Configuration
public class FeignConfiguration implements RequestInterceptor {

    @Override
    public void apply(RequestTemplate requestTemplate) {
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        requestTemplate.header("x-username", request.getHeader("x-username"));
    }

}

 

上一篇:Openfeign原理


下一篇:Makefile选项CFLAGS,LDFLAGS,LIBS