mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2025-01-05 18:42:22 +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.boot.web.servlet.ServletRegistrationBean;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
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.RequestContextHolder;
|
||||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
import org.springframework.web.servlet.DispatcherServlet;
|
import org.springframework.web.servlet.DispatcherServlet;
|
||||||
@ -42,8 +43,9 @@ public class FeignConfig {
|
|||||||
@Bean
|
@Bean
|
||||||
public RequestInterceptor requestInterceptor() {
|
public RequestInterceptor requestInterceptor() {
|
||||||
return (template) -> {
|
return (template) -> {
|
||||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder
|
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
|
||||||
.getRequestAttributes();
|
if (requestAttributes != null) {
|
||||||
|
ServletRequestAttributes attributes = (ServletRequestAttributes) requestAttributes;
|
||||||
HttpServletRequest request = attributes.getRequest();
|
HttpServletRequest request = attributes.getRequest();
|
||||||
//获取请求头
|
//获取请求头
|
||||||
Enumeration<String> headerNames = request.getHeaderNames();
|
Enumeration<String> headerNames = request.getHeaderNames();
|
||||||
@ -55,6 +57,7 @@ public class FeignConfig {
|
|||||||
template.header(name, values);
|
template.header(name, values);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user