EasyExcel使用问题 junit测试不用response就没有问题 但在web中使用

使用EasyExcel对线上的excel文件进行数据填充之后导出文件
在junit中使用是能够正常编译并生成文件的 但在web中测试就会报错
下载文件失败Copy template failure.

这句话EasyExcel.write(response.getOutputStream()).withTemplate(in).build();
的build会报错,com.alibaba.excel.exception.ExcelGenerateException: Copy template failure.

ExcelWriter excelWriter = null;
ServletOutputStream outputStream = null;
try {
    response.setContentType("application/vnd.ms-excel");
    response.setCharacterEncoding("utf-8");
    String fileName = URLEncoder.encode("temp", "UTF-8");
    response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");

    outputStream = response.getOutputStream();
    ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).withTemplate(in).build();
    WriteSheet writeSheet = EasyExcel.writerSheet().build();
    excelWriter.fill(reportNum, writeSheet);
    } catch (Exception e) {
        response.reset();
        response.setContentType("application/json");
        response.setCharacterEncoding("utf-8");
        Map<String, String> map = new HashMap<String, String>();
        map.put("status", "failure");
        map.put("message", "下载文件失败" + e.getMessage());
        response.getWriter().println(JSON.toJSONString(map));
    } finally {
            if(outputStream!=null){
                outputStream.flush();
            }
            if (excelWriter != null) {
                excelWriter.finish();
            }
            if (in != null) {
                in.close();
            }
        }

请问各位大牛 是我哪里写得有问题吗?

采用inputStream的template方式可以了,原因是部署在服务器上没有读到正确的文件。
springboot项目,test.xlsx在resource/template/路径下。部署的是jar包。

InputStream templatePathName = this.getClass().getClassLoader().getResourceAsStream("template/test.xlsx");
ByteArrayOutputStream out = new ByteArrayOutputStream();
excelWriter = EasyExcel.write().file(out).withTemplate(templatePathName).build();

使用EasyExcel对线上的excel文件进行数据填充之后导出文件
在junit中使用是能够正常编译并生成文件的 但在web中测试就会报错
下载文件失败Copy template failure.

这句话EasyExcel.write(response.getOutputStream()).withTemplate(in).build();
的build会报错,com.alibaba.excel.exception.ExcelGenerateException: Copy template failure.

一样的问题