异常信息如下:
2022-12-21 03:55:22.682 ERROR 2136 --- [nio-8088-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.InternalError: java.lang.reflect.InvocationTargetException] with root cause
java.lang.NullPointerException: Cannot load from short array because "sun.awt.FontConfiguration.head" is null
at java.desktop/sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1262) ~[na:na]
at java.desktop/sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:224) ~[na:na]
at java.desktop/sun.awt.FontConfiguration.init(FontConfiguration.java:106) ~[na:na]
at java.desktop/sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:706) ~[na:na]
at java.desktop/sun.font.SunFontManager$2.run(SunFontManager.java:358) ~[na:na]
at java.desktop/sun.font.SunFontManager$2.run(SunFontManager.java:315) ~[na:na]
at java.base/java.security.AccessController.doPrivileged(AccessController.java:318) ~[na:na]
系统环境:Centos7
、JDK17
原因分析:根据异常信息可以看出是系统中缺少相应的字体库。
解决办法:安装fontconfig
库即可解决,执行如下命令:
yum install -y fontconfig
fc-cache --force
然后重启服务,验证码就可以正常显示了。