使用背景
:今天在spring-cloud项目中,使用多线程异步调用微服务出现的错误
No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request。
具体场景
:
我的微服务调用有自己的统一拦截器RequestIntercepter来输出调用信息,在其中使用RequestContextHolder来获取request信息,发现异步调用时,主线程结束后,子线程就获取不到request,会报以上错误信息。
解决思路:
1.将主线程的request和session信息放进ThreadLocal里,透传到子线程再去获取,这种我还没试(稍后有时间弄)。
2.在开启新线程之前,将servletRequestAttributes设置为子线程共享
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
RequestContextHolder.setRequestAttributes(servletRequestAttributes,true);//设置子线程共享
背景2:如果非web请求(定时任务或者消息消费)造成的,可以通过以下方式设置,在触发报错的类里面加上一个自己封装的方法getRequestAttributesSafely(),具体可以参考下面:
public RequestAttributes getRequestAttributesSafely(){
RequestAttributes requestAttributes = null;
requestAttributes = RequestContextHolder.currentRequestAttributes();
}catch (IllegalStateException e){
requestAttributes = new NonWebRequestAttributes();
return requestAttributes;
解决No thread-bound request found: Are you referring to request attributes outside of an actual web re
使用背景:今天在spring-cloud项目中,使用多线程异步调用微服务出现的错误Nothread-boundrequestfound:Areyoureferringtorequestattributesoutsideofanactualwebrequest,orprocessingarequestoutsideoftheoriginallyr...
dispatch:装订文件
一个Meteor程序包,它向MongoDB和MiniMongo文档提取添加了一个{bind: true}选项。 使用它时,返回的文档是BoundDocument实例,它将在您设置数据库属性时更新数据库。
适用于所有集合类型,托管或非托管,本地或远程
适用于客户端和服务器代码
适用于深度嵌套的属性,但不适用于数组
$ meteor add dispatch:bound-document
只有在将SimpleSchema附加到集合后, bind选项才起作用。 参见 。
支持绑定的功能
cursor.fetch
cursor.forEach
cursor.map
collection.findOne
// Initialize the collection and attach a schema
var c = new Mongo
JAVA分布式项目中报错:No thread-bound request found: Are you referring to request attributes…
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
CompletableFuture.supplyAsync(() -> {
RequestContextHolder.setRequestAttributes(servletRequestAttrib.
No thread-bound request found: Are you referring to request attributes outside of an actual web requ
No thread-bound request found: " +
"Are you referring to request attributes outside of an actual web request, " +
"or processing a request outside of the originally receiving thread?
该存储库是规范草案的来源,用于扩展OpenID Connect提供程序以支持证书的颁发,从而支持围绕身份信息联合共享的新方法。
主要规范是用markdown编写的,但是要预览您在最终格式中所做的更改,可以按照以下步骤进行。
工具markdown2rfc用于将原始markdown表示形式转换为HTML和XML格式。 为了运行此工具,您必须安装了 。
使用所需的更改更新spec.md文件。
运行以下命令,将新的txt编译为输出HTML和XML。
./scripts/build-html.sh
微服务Feign调用后开启Schedule定时任务后报错
No thread-bound request found: Are you referring to request attributes outsid
此方法用于:单独调用接口没问题,开启定时任务就报错
解决方法
FeignClient类方法加参数@RequestHeader(“from”) String from
@RequestMapping(value = "/user/list", method = RequestMethod.GET
解决No thread-bound request found: Are you referring to request attributes outside of an actual web re
56460
解决No thread-bound request found: Are you referring to request attributes outside of an actual web re
hkf仙:
win10解决cmd无法切换盘符的问题
m0_67267159:
win10报错jar不是内部或外部命令,也不是可运行的程序
Cz_114514: