[alibaba/easyexcel]EasyExcel版本2.1.4,poi版本3.17,withTemplate模板写入时,main方法测试正常,通过接口调用,在service中执行失败

2024-05-23 326 views
1

触发场景描述 public static void main(String args[]) { System.out.println("Hello World!"); doExport("20191225"); } private static void doExport(String day) { String name = "模板15"; String templateFileName = FileUtil.getPath() + "demo" + File.separator + "fill" + File.separator + name + ".xlsx"; boolean isExists = new File(templateFileName).exists(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss"); String str = sdf.format(new Date()); String fileName = FileUtil.getPath() + name + " - " + str + ".xlsx"; String fileNameFinal = FileUtil.getPath() + name + "- 最后数据 - " + str + ".xlsx"; String imagePath = FileUtil.getPath() + name + str + ".png"; String imagePathFinal = FileUtil.getPath() + name + "- 最后数据 - " + str + ".png"; ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build(); }

描述: 1、doExport()方法在main()方法中执行正常,可以生成新的excel文件

  1. 通过接口访问(Controller->ServiceImpl)中调用doExport()方法,则失败(未生成新的excel文件,服务自动重启)。

触发Bug的代码 ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build();


**提示的异常或者没有达到的效果**
1.并没有生成新的excel文件,且会自动重启服务。
2.提示Shutting down ExecutorService 'applicationTaskExecutor' 
[Thread-4 com.zaxxer.hikari.HikariDataSource] - HikariPool-1 - Shutdown initiated...
[Thread-4 com.zaxxer.hikari.HikariDataSource] - HikariPool-1 - Shutdown completed.

回答

2

帮忙看下,弄这个快一周时间了。。。

4

" EasyExcel.write(outPath,DataVO.class).withTemplate(templateFileName).sheet(0) .relativeHeadRowIndex(6).automaticMergeHead(true).doWrite(dataList);" 我这样写的没报错,但是,生成的文件还是模板,没有写入数据

8

能不能贴一下异常?

5

在执行org.apache.poi.xssf.usermodel.XSSFFactory这个类的createDocumentPart方法时, protected POIXMLDocumentPart createDocumentPart (Class<? extends POIXMLDocumentPart> cls, Class<?>[] classes, Object[] values) throws SecurityException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException { Constructor<? extends POIXMLDocumentPart> constructor = cls.getDeclaredConstructor(classes); //此时会有以下警告 ([WARN 2019-12-26 16:23:17,437] [HikariPool-1 housekeeper com.zaxxer.hikari.pool.HikariPool] - HikariPool-1 - Thread starvation or clock leap detected (housekeeper delta=1m23s749ms). ) // 此方法(newInstance)后,会 Shutting down return constructor.newInstance(values); //////// [INFO 2019-12-26 16:25:02,828] [Thread-4 org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor] - Shutting down ExecutorService 'applicationTaskExecutor' [INFO 2019-12-26 16:25:02,833] [Thread-4 com.zaxxer.hikari.HikariDataSource] - HikariPool-1 - Shutdown initiated... [INFO 2019-12-26 16:25:02,883] [Thread-4 com.zaxxer.hikari.HikariDataSource] - HikariPool-1 - Shutdown completed. }

在控制台中,并没有错误信息提示,都被poi的接口catch住了。

9

我也出现了这个问题,执行导出操作,导出成功了,但是项目会自动重启,没有任何异常。 2022-08-19 10:57:58.227 INFO 32496 --- [ Thread-44] o.s.a.r.l.SimpleMessageListenerContainer : Waiting for workers to finish. 2022-08-19 10:57:58.730 INFO 32496 --- [ Thread-44] o.s.a.r.l.SimpleMessageListenerContainer : Successfully waited for workers to finish. 2022-08-19 10:57:59.664 INFO 32496 --- [ Thread-44] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated... 2022-08-19 10:57:59.684 INFO 32496 --- [ Thread-44] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed. 2022-08-19 10:57:59.685 INFO 32496 --- [ Thread-44] .c.NacosValueAnnotationBeanPostProcessor : class com.alibaba.nacos.spring.context.annotation.config.NacosValueAnnotationBeanPostProcessor was destroying! 2022-08-19 10:57:59.685 INFO 32496 --- [ Thread-44] AnnotationNacosInjectedBeanPostProcessor : class com.alibaba.nacos.spring.beans.factory.annotation.AnnotationNacosInjectedBeanPostProcessor was destroying!