简介:在使用到跨服务间的接口调用(同一个系统需要分离出管理端和业务端【同一登录】),会遇到一个问题就是token转发
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.ObjectUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
/**
* 请求头转发配置(token转发)
* @author
*/
@Configuration
public class FeignConfiguration implements RequestInterceptor {
@Override
public void apply(RequestTemplate requestTemplate) {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder
.getRequestAttributes();
if(!ObjectUtils.isEmpty(attributes)){
HttpServletRequest request = attributes.getRequest();
if (!ObjectUtils.isEmpty(req