验证码kaptcha组件(DefaultKaptcha)在本地开发环境没有问题,发到测试环境就报错的解决方案

之前一直运行好好地系统今天发布到测试环境突然就不行了,但是试了很多办法,发现本地和开发环境都是可以的,该引入的依赖也引入了

<dependency>
	<groupId>com.github.penggle</groupId>
	    <artifactId>kaptcha</artifactId>
	    <version>2.3.2</version>
    <exclusions>
        <exclusion>
	            <artifactId>javax.servlet-api</artifactId>
	            <groupId>javax.servlet</groupId>
        </exclusion>
    </exclusions>
</dependency>

验证码相关的代码最近也没动过,本地测试接口也正常返回数据,controller如下:

	ServletOutputStream out = null;
        try {
            HttpSession session = request.getSession();
            response.setDateHeader("Expires", 0);
            response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
            response.addHeader("Cache-Control", "post-check=0, pre-check=0");
            response.setHeader("Pragma", "no-cache");
            response.setContentType("image/jpeg");

            String type = request.getParameter("type");
            String capStr = null;
            String code = null;
            BufferedImage bi = null;
            if ("math".equals(type)) {
                String capText = captchaProducerMath.createText();
                capStr = capText.substring(0, capText.lastIndexOf("@"));
                code = capText.substring(capText.lastIndexOf("@") + 1);
                bi = captchaProducerMath.createImage(capStr);
            } else if ("char".equals(type)) {
                capStr = code = captchaProducer.createText();
                bi = captchaProducer.createImage(capStr);
            }
            session.setAttribute(Constants.KAPTCHA_SESSION_KEY, code);
            out = response.getOutputStream();
            ImageIO.write(bi, "jpg", out);
            out.flush();
          } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (out != null) {
                    out.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return null;      

解决方案:

最后怀疑是操作系统的问题,操作系统没有FontConfig组件,解决办法 安装相应字体配置组件,需要执行两条命令:

yum install fontconfig
fc-cache –force
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值