Commit 4f29e256 by 袁伟铭

1.0.0

parent 67b8c593
package com.zq.api.config;
import com.zq.common.http.HttpRequestUtils;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
@Configuration
public class FeignConfig {
/**
* 解决fein远程调用丢失请求头
*
* @return
*/
@Bean
public RequestInterceptor requestInterceptor() {
return new RequestInterceptor() {
@Override
public void apply(RequestTemplate template) {
HttpServletRequest request = HttpRequestUtils.getRequest();
template.header("X-App-Token", request.getParameter("token"));
Enumeration<String> headerNames = request.getHeaderNames();
if (headerNames != null) {
while (headerNames.hasMoreElements()) {
String name = headerNames.nextElement();
String values = request.getHeader(name);
template.header(name, values);
}
}
}
};
}
}
package com.zq.api.feign;
import com.zq.api.config.FeignConfig;
import com.zq.common.vo.ResultVo;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
......@@ -7,7 +8,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import java.util.Map;
@FeignClient(name = "CMS-SERVER") //指定调用哪个微服务
@FeignClient(name = "CMS-SERVER", configuration = FeignConfig.class) //指定调用哪个微服务
@RequestMapping("/cms")
public interface CmsFeign {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment