加入一个bean
代码语言:javascript复制@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空指针异常");
}
};
}