【发布时间】:2021-07-13 17:03:49
【问题描述】:
我们的项目中有一个平均在 30 秒内返回的端点, 因此,我们建议将此端点设为异步
但是,使用时服务不再工作
@PostMapping("/alocacaoPorPeriodo")
public void alocacaoPorPeriodo(@RequestParam(required = true) Date dataInicio, @RequestParam(required = true) Date dataFim) {
CompletableFuture.runAsync(() -> alocacaoServive.alocarPorPeriodo(dataInicio, dataFim));
}
服务调用从 jpa 存储库中删除、保存或更新方法时发生错误。获取方法仍然有效。
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: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
这是我们为实现异步所做的独特更改,我是不是忘记了什么?
谢谢
【问题讨论】:
-
你的班级有
@EnableAsync吗? -
您可能在您的服务中使用
RequestContextHolder.getCurrentRequestAttributes()或请求范围的对象。