Openjdk1.8字体缺失导致获取图片验证码出错

问题

1
2
3
4
5
6
7
8
9
10
Caused by: java.lang.NullPointerException: null
at sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264) ~[na:1.8.0_151]
at sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:219) ~[na:1.8.0_151]
at sun.awt.FontConfiguration.init(FontConfiguration.java:107) ~[na:1.8.0_151]
at sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:774) ~[na:1.8.0_151]
at sun.font.SunFontManager$2.run(SunFontManager.java:431) ~[na:1.8.0_151]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_151]
at sun.font.SunFontManager.<init>(SunFontManager.java:376) ~[na:1.8.0_151]
at sun.awt.FcFontManager.<init>(FcFontManager.java:35) ~[na:1.8.0_151]
at sun.awt.X11FontManager.<init>(X11FontManager.java:57) ~[na:1.8.0_151]

原因

Openjdk1.8字体缺失导致

解决方案

只需要在项目的dockerFile部署文件里面添加下面这一条即可:

RUN apk add –update ttf-dejavu fontconfig

补充

但是加了之后项目构建会变得很慢。这之后需要切换使用国内镜像,具体写法如下:

1
2
3
4
5
# Install cURL
RUN echo -e "https://mirror.tuna.tsinghua.edu.cn/alpine/v3.4/main\n\
https://mirror.tuna.tsinghua.edu.cn/alpine/v3.4/community" > /etc/apk/repositories
ENV LANG en_US.UTF-8
RUN apk add --update ttf-dejavu fontconfig && rm -rf /var/cache/apk/*