mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2025-01-03 17:42:20 +08:00
fix(FeignConfig.class): feign拦截器添加RequestAttributes是否为空的判断,MQ监听调用时为null
This commit is contained in:
parent
c7bb7d206f
commit
996fd7b328
@ -5,6 +5,7 @@ import feign.RequestInterceptor;
|
||||
import org.springframework.boot.web.servlet.ServletRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import org.springframework.web.servlet.DispatcherServlet;
|
||||
@ -42,8 +43,9 @@ public class FeignConfig {
|
||||
@Bean
|
||||
public RequestInterceptor requestInterceptor() {
|
||||
return (template) -> {
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder
|
||||
.getRequestAttributes();
|
||||
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
|
||||
if (requestAttributes != null) {
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) requestAttributes;
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
//获取请求头
|
||||
Enumeration<String> headerNames = request.getHeaderNames();
|
||||
@ -55,6 +57,7 @@ public class FeignConfig {
|
||||
template.header(name, values);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user