多线程异步操作导致异步线程获取不到主线程的request信息
2020-06-28 17:47 话猫 阅读(2077) 评论(0) 编辑 收藏 举报org.springframework.web.context.request.RequestContextHolder
org.springframework.web.context.request.RequestAttributes
org.springframework.web.context.request.ServletRequestAttributes
开启新线程之前,添加代码:
// 将RequestAttributes对象设置为子线程共享
ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
RequestContextHolder.setRequestAttributes(sra, true);