Spring 启动 + Botdetect 验证码:输入流不能为空

Spring Boot + Botdetect Captcha: Inputstream cannot be null

我试过在 Spring 启动时使用 botdetetect 验证码。一切正常,验证码显示它可以检测它是否是人类。但是每当我使用验证码进入登录屏幕时,我都会不断收到此错误堆栈:

2018-08-02 12:09:01.074 ERROR 25196 --- [nio-8080-exec-2] .c.SimpleCaptchaFileConfigurationFactory : SimpleXmlConfigurationLoader.load() java.lang.IllegalArgumentException: InputStream cannot be null

这是我的文件夹结构:

我想知道它是否没有检测到 botdetect.xml 这就是它出现该错误的原因。如何在不放置新的 WEB-INF 文件夹的情况下添加它?

在他们的教程中找到了答案https://captcha.com/doc/java/captcha-options.html#simple-api

将此添加到配置 class:

@Bean
public ServletContextInitializer initializer() {
  return new ServletContextInitializer() {

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
      servletContext.setInitParameter("BDC_configFileLocation", "/resources/botdetect.xml");
    }
  };
}