/tmp/tomcat /work/Tomcat/localhost/RooT/upload_*****.tmp (No such file or directory)

这个问题出现在异步执行导入解析excel文件时出现的错误,原因大概时主线程跑的比解析执行excel的线程快删除了临时excel,导致异步解析excel时找不到文件
代码如下

    @RequestMapping(value = "/model/excelImport", method = {RequestMethod.POST})
    public R modelExcelImport(@RequestParam("fileName") MultipartFile file, HttpServletRequest request) {
        return handle(request, (user, r) -> {
            asyncImportService.batchUpdateModelMapping(file, user);
            r = R.ok("文件异步上传完成,请等待后续执行过程");
            return r;
        });
    }

其中 asyncImportService.batchUpdateModelMapping(file, user)执行异步业务
参考了以下连接

【报错记录】SpringBoot中MultipartFile上传报/tmp/tomcat.***.tmp (No such file or directory)
Spring boot 【异步调用】 之 上传文件图片 java.io.IOException: java.io.FileNotFoundException 异常

之后的解决方案为:在主线程临时保存一份file
修改后的代码

    @RequestMapping(value = "/model/excelImport", method = {RequestMethod.POST})
    public R modelExcelImport(@RequestParam("fileName") MultipartFile file, HttpServletRequest request) {
        return handle(request, (user, r) -> {
            String fileName = file.getOriginalFilename();
            String prefix = fileName.substring(fileName.lastIndexOf("."));
            File excelFile = File.createTempFile(System.currentTimeMillis() + "", prefix);
            file.transferTo(excelFile);
            asyncImportService.batchUpdateModelMapping(excelFile, user);
            r = R.ok("文件异步上传完成,请等待后续执行过程");
            return r;
        });
    }

将MultipartFile 转为file时,记得asyncImportService.batchUpdateModelMapping(excelFile, user);的方法中excelFile是file类型,不是原来的MultipartFile 类型.解析excel的代码记得改一下方法.
或者在转为MultipartFile 在调用异步方法.file转MultipartFile …emm,不会…而且感觉有点呆

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值