美文网首页
EasyExcel FontConfiguration getV

EasyExcel FontConfiguration getV

作者: 极简架构 | 来源:发表于2023-08-22 21:12 被阅读0次

    1.问题:

    使用最版本 easyexcel 3.3.2 ,升级了Dockerfile依赖的基础镜像版本,导出excel时 报错 NullPointerException


    image.png

    环境说明:

    SpringBoot 2.3.5
    JDK8
    pom.xml 依赖 easyexcel 版本为 3.3.2

             <!-- easyexcel -->
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>easyexcel</artifactId>
                <version>3.3.2</version>
            </dependency>
    
    2023-08-23 20:16:38.386 ERROR [http-nio-7001-exec-10] c.a.e.i.a.w.c.a.xxController.exportExcel:118 -  exporteExcel failed
    
    java.lang.NullPointerException: null
    
        at sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264)
    
        at sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:219)
    
        at sun.awt.FontConfiguration.init(FontConfiguration.java:107)
    
        at sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:774)
    
        at sun.font.SunFontManager$2.run(SunFontManager.java:431)
    
        at java.security.AccessController.doPrivileged(Native Method)
    
        at sun.font.SunFontManager.<init>(SunFontManager.java:376)
    
        at sun.awt.FcFontManager.<init>(FcFontManager.java:35)
    
        at sun.awt.X11FontManager.<init>(X11FontManager.java:57)
    
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    
        at java.lang.Class.newInstance(Class.java:442)
    
        at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:83)
    
        at java.security.AccessController.doPrivileged(Native Method)
    
        at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
    
        at java.awt.Font.getFont2D(Font.java:495)
    
        at java.awt.Font.canDisplayUpTo(Font.java:2080)
    
        at java.awt.font.TextLayout.singleFont(TextLayout.java:470)
    
        at java.awt.font.TextLayout.<init>(TextLayout.java:531)
    
        at org.apache.poi.ss.util.SheetUtil.getDefaultCharWidth(SheetUtil.java:273)
    
        at org.apache.poi.xssf.streaming.AutoSizeColumnTracker.<init>(AutoSizeColumnTracker.java:117)
    
        at org.apache.poi.xssf.streaming.SXSSFSheet.<init>(SXSSFSheet.java:82)
    
        at org.apache.poi.xssf.streaming.SXSSFWorkbook.createAndRegisterSXSSFSheet(SXSSFWorkbook.java:684)
    
        at org.apache.poi.xssf.streaming.SXSSFWorkbook.createSheet(SXSSFWorkbook.java:705)
    
        at org.apache.poi.xssf.streaming.SXSSFWorkbook.createSheet(SXSSFWorkbook.java:88)
    
        at com.alibaba.excel.util.WorkBookUtil.createSheet(WorkBookUtil.java:86)
    
        at com.alibaba.excel.context.WriteContextImpl.createSheet(WriteContextImpl.java:223)
    
        at com.alibaba.excel.context.WriteContextImpl.initSheet(WriteContextImpl.java:182)
    
        at com.alibaba.excel.context.WriteContextImpl.currentSheet(WriteContextImpl.java:135)
    
        at com.alibaba.excel.write.ExcelBuilderImpl.addContent(ExcelBuilderImpl.java:54)
    
        at com.alibaba.excel.ExcelWriter.write(ExcelWriter.java:73)
    
        at com.alibaba.excel.ExcelWriter.write(ExcelWriter.java:50)
    
        at com.xxController.exportExcel(xxController.java:114)
    
        at com.xxController$$FastClassBySpringCGLIB$$8f808946.invoke(<generated>)
    
        at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
    
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:771)
    
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
    
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
    
        at org.springframework.validation.beanvalidation.MethodValidationInterceptor.invoke(MethodValidationInterceptor.java:119)
    
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
    
        at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691)
    
        at com.xxController$$EnhancerBySpringCGLIB$$11cb1236.exportExcel(<generated>)
    
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    
        at java.lang.reflect.Method.invoke(Method.java:498)
    
        at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
    
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
    
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)
    
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:878)
    
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:792)
    
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
    
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
    
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
    
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
    
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
    
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:652)
    
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
    
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
    
        at sun.reflect.GeneratedMethodAccessor178.invoke(Unknown Source)
    
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    
        at java.lang.reflect.Method.invoke(Method.java:498)
    
        at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:282)
    
        at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:279)
    
        at java.security.AccessController.doPrivileged(Native Method)
    
        at javax.security.auth.Subject.doAsPrivileged(Subject.java:549)
    
        at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:314)
    
        at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:170)
    
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:225)
    
        at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:47)
    
        at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:149)
    
        at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:145)
    
        at java.security.AccessController.doPrivileged(Native Method)
    
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:144)
    
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    
        at sun.reflect.GeneratedMethodAccessor83.invoke(Unknown Source)
    
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    
        at java.lang.reflect.Method.invoke(Method.java:498)
    
        at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:282)
    
        at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:279)
    
        at java.security.AccessController.doPrivileged(Native Method)
    
        at javax.security.auth.Subject.doAsPrivileged(Subject.java:549)
    
        at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:314)
    
        at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:253)
    
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:191)
    
        at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:47)
    
        at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:149)
    
        at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:145)
    
        at java.security.AccessController.doPrivileged(Native Method)
    
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:144)
    
        at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:93)
    
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    
        at sun.reflect.GeneratedMethodAccessor83.invoke(Unknown Source)
    
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    
        at java.lang.reflect.Method.invoke(Method.java:498)
    
        at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:282)
    
        at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:279)
    
        at java.security.AccessController.doPrivileged(Native Method)
    
        at javax.security.auth.Subject.doAsPrivileged(Subject.java:549)
    
        at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:314)
    
        at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:253)
    
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:191)
    
        at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:47)
    
        at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:149)
    
        at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:145)
    
        at java.security.AccessController.doPrivileged(Native Method)
    
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:144)
    
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
    
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    
        at sun.reflect.GeneratedMethodAccessor83.invoke(Unknown Source)
    
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    
        at java.lang.reflect.Method.invoke(Method.java:498)
    
        at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:282)
    
        at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:279)
    
        at java.security.AccessController.doPrivileged(Native Method)
    
        at javax.security.auth.Subject.doAsPrivileged(Subject.java:549)
    
        at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:314)
    
        at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:253)
    
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:191)
    
        at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:47)
    
        at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:149)
    
        at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:145)
    
        at java.security.AccessController.doPrivileged(Native Method)
    
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:144)
    
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
    
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
    
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
    
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)
    
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
    
        at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:747)
    
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
    
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
    
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
    
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
    
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590)
    
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152)
    
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:627)
    
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    
        at java.lang.Thread.run(Thread.java:882)
    
    

    2.问题原因

    EasyExcel导出时, 时需要用到的字体,升级新的基础镜像 java:8-jre-alpine 中没有相关字体包,导致导出excel NPE报错

    3.fix方案

    项目采用容器化部署,修改Dockerfile 安装相关字体包即可
    Dockerfile中添加一句话,修改后重新打包image,导出excel正常,问题fix

    # easy-excel 安装字体包,修复 FontConfiguration NTE 问题
    RUN yum -y install fontconfig
    

    apk安装也可
    RUN apk add --update --no-cache ttf-dejavu fontconfig

    4.相关issue

    https://github.com/docker-library/openjdk/issues/73

    相关文章

      网友评论

          本文标题:EasyExcel FontConfiguration getV

          本文链接:https://www.haomeiwen.com/subject/efiumdtx.html