加入一个bean
@Bean("requestInterceptor")
public RequestInterceptor requestInterceptor(){
return template -> {
ServletRequestAttributes attributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
if(attributes!=null){
HttpServletRequest request = attributes.getRequest();
if (null == request){
return;
}
log.info(request.getHeaderNames().toString());
template.header("token", request.getHeader("token"));
}else {
log.warn("requestInterceptor获取Header空指针异常");
}
};
}