package de.gdv.sp.configuration;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.captcha.botdetect.web.servlet.CaptchaServlet;
@Configuration
public class CaptchaConfiguration {
@Bean(name = "captchaServlet")
public ServletRegistrationBean captchaServlet() {
return new ServletRegistrationBean(new CaptchaServlet(), "/kontakt");
}
}
我试图在我们的Spring MVC / Boot项目中实现BotDetect验证码。当我尝试创建带注释的servlet(不带web.xml)时,总是得到以下屏幕信息:screenshot of http://localhost:8080/kontakt
此外,当我编写此验证码的HTML代码时,会得到以下结果。Botdetect Captcha does not show picture
<botDetect:captcha id="exampleCaptcha"/>
<div class="validationDiv">
<input id="captchaCode" type="text" name="captchaCode"
value="${basicExample.captchaCode}"/>
<input type="submit" name="submit" value="Submit" />
<span class="correct">${basicExample.captchaCorrect}</span>
<span class="incorrect">${basicExample.captchaIncorrect}</span>
</div>
我怎么解决这个问题?
[BotDetect验证码网站] [3]
最佳答案
您可以尝试:
扩展WebApplicationInitializer
package de.gdv.sp.configuration;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.captcha.botdetect.web.servlet.CaptchaServlet;
@Configuration
public class CaptchaConfiguration extends WebApplicationInitializer {
@Bean(name = "captchaServlet")
public ServletRegistrationBean captchaServlet() {
return new ServletRegistrationBean(new CaptchaServlet(), "/kontakt");
}
}
将您的bean定义移到扩展WebApplicationInitializer的类中。
@Configuration
public class WebXMLReplacement extends WebApplicationInitializer {
//other configurations
@Bean(name = "captchaServlet")
public ServletRegistrationBean captchaServlet() {
return new ServletRegistrationBean(new CaptchaServlet(), "/kontakt");
}
}