最近使用EasyExcel开发excel导出功能遇到一个坑点,记录一下。
问题:导出时报错,本地测试不会报错,只有部署到服务器上才报错。
错误日志:
JDBC Connection [@4e998982] will not be managed by Spring
Closing non transactional SqlSession [@73c1a8d6]
2021-12-06 14:20:15.388 ERROR 42 defaultErrorHandler - fatal exception, a={}, b={} : null
at (:1264) ~[?:1.8.0_41]
at (:219) ~[?:1.8.0_41]
at (:107) ~[?:1.8.0_41]
at .(:776) ~[?:1.8.0_41]
at $(:431) ~[?:1.8.0_41]
at (Native Method) ~[?:1.8.0_41]
at .<init>(:376) ~[?:1.8.0_41]
at .X11FontManager.<init>(:57) ~[?:1.8.0_41]
at .newInstance0(Native Method) ~[?:1.8.0_41]
at (:62) ~[?:1.8.0_41]
at (:45) ~[?:1.8.0_41]
at (:422) ~[?:1.8.0_41]
at (:442) ~[?:1.8.0_41]
at $(:83) ~[?:1.8.0_41]
at (Native Method) ~[?:1.8.0_41]
at (:74) ~[?:1.8.0_41]
at .getFont2D(:491) ~[?:1.8.0_41]
at (:2060) ~[?:1.8.0_41]
at (:470) ~[?:1.8.0_41]
at .<init>(:531) ~[?:1.8.0_41]
at (:275) ~[poi-3.:3.17]
at .<init>(:117) ~[poi-ooxml-3.:3.17]
at .<init>(:82) ~[poi-ooxml-3.:3.17]
at (:658) ~[poi-ooxml-3.:3.17]
at (:679) ~[poi-ooxml-3.:3.17]
at (:90) ~[poi-ooxml-3.:3.17]
at (:66) ~[easyexcel-2.2.:?]
at (:205) ~[easyexcel-2.2.:?]
at (:185) ~[easyexcel-2.2.:?]
at (:122) ~[easyexcel-2.2.:?]
at (:53) ~[easyexcel-2.2.:?]
at (:161) ~[easyexcel-2.2.:?]
at (:146) ~[easyexcel-2.2.:?]
at (:61) ~[easyexcel-2.2.:?]
at .(:100) ~[classes/:1.0.0]
at .$$FastClassBySpringCGLIB$$(<generated>) ~[classes/:1.0.0]
at (:218) ~[spring-core-5.2.:5.2.]
at $(:771) ~[spring-aop-5.2.:5.2.]
at (:163) ~[spring-aop-5.2.:5.2.]
at $(:749) ~[spring-aop-5.2.:5.2.]
at (:55) ~[spring-aop-5.2.:5.2.]
at (:186) ~[spring-aop-5.2.:5.2.]
at $(:749) ~[spring-aop-5.2.:5.2.]
at (:56) ~[spring-aop-5.2.:5.2.]
at (:186) ~[spring-aop-5.2.:5.2.]
at $(:749) ~[spring-aop-5.2.:5.2.]
at (:95) ~[spring-aop-5.2.:5.2.]
at (:186) ~[spring-aop-5.2.:5.2.]
at $(:749) ~[spring-aop-5.2.:5.2.]
at $(:691) ~[spring-aop-5.2.:5.2.]
at .$$EnhancerBySpringCGLIB$$(<generated>) ~[classes/:1.0.0]
at .invoke0(Native Method) ~[?:1.8.0_41]
at (:62) ~[?:1.8.0_41]
at (:43) ~[?:1.8.0_41]
at (:497) ~[?:1.8.0_41]
at (:190) ~[spring-web-5.2.:5.2.]
at (:138) ~[spring-web-5.2.:5.2.]
at (:105) ~[spring-webmvc-5.2.:5.2.]
at (:878) ~[spring-webmvc-5.2.:5.2.]
at (:792) ~[spring-webmvc-5.2.:5.2.]
at (:87) ~[spring-webmvc-5.2.:5.2.]
at (:1040) [spring-webmvc-5.2.:5.2.]
at (:943) [spring-webmvc-5.2.:5.2.]
at (:1006) [spring-webmvc-5.2.:5.2.]
at (:898) [spring-webmvc-5.2.:5.2.]
at (:626) [:4.]
at (:883) [spring-webmvc-5.2.:5.2.]
at (:733) [:4.]
at (:231) [:9.0.41]
at (:166) [:9.0.41]
at (:53) [:9.0.41]
at (:193) [:9.0.41]
at (:166) [:9.0.41]
at (:92) [spring-web-5.2.:5.2.]
at (:119) [spring-web-5.2.:5.2.]
at (:193) [:9.0.41]
at (:166) [:9.0.41]
at (:124) [druid-1.1.:1.1.22]
at (:193) [:9.0.41]
at (:166) [:9.0.41]
at (:56) [classes/:1.0.0]
at (:193) [:9.0.41]
at (:166) [:9.0.41]
at (:100) [spring-web-5.2.:5.2.]
at (:119) [spring-web-5.2.:5.2.]
at (:193) [:9.0.41]
at (:166) [:9.0.41]
at (:93) [spring-web-5.2.:5.2.]
at (:119) [spring-web-5.2.:5.2.]
at (:193) [:9.0.41]
at (:166) [:9.0.41]
at (:126) [spring-boot-2.2.:2.2.]
at $000(:64) [spring-boot-2.2.:2.2.]
at $(:101) [spring-boot-2.2.:2.2.]
at (:119) [spring-web-5.2.:5.2.]
at (:119) [spring-boot-2.2.:2.2.]
at (:193) [:9.0.41]
at (:166) [:9.0.41]
at (:201) [spring-web-5.2.:5.2.]
at (:119) [spring-web-5.2.:5.2.]
at (:193) [:9.0.41]
at (:166) [:9.0.41]
at (:202) [:9.0.41]
at (:97) [:9.0.41]
at (:542) [:9.0.41]
at (:143) [:9.0.41]
at (:92) [:9.0.41]
at (:690) [:9.0.41]
at (:78) [:9.0.41]
at (:343) [:9.0.41]
at .http11.(:374) [:9.0.41]
at (:65) [:9.0.41]
at $(:888) [:9.0.41]
at $(:1597) [:9.0.41]
at (:49) [:9.0.41]
at (:1142) [?:1.8.0_41]
at $(:617) [?:1.8.0_41]
at $(:61) [:9.0.41]
at (:745) [?:1.8.0_41]
原因:服务器上没有安装字体包导致的!
解决方案:
方法1,给服务器安装字体包(亲测可用):
a,安装字体包: yum -y install fontconfig
b,刷新内存中的字体缓存: fc-cache
c,查看字体是否安装成功(有一种即可): fc-list
d,重启项目(不必重启服务器)。
方法2,更换Oracle JDK,不要使用openJDK。