ImageVerifyCodeConfig.java 1.2 KB

12345678910111213141516171819202122232425262728
  1. package com.ym.mec.web.config;
  2. import com.google.code.kaptcha.impl.DefaultKaptcha;
  3. import com.google.code.kaptcha.util.Config;
  4. import org.springframework.context.annotation.Bean;
  5. import org.springframework.context.annotation.Configuration;
  6. import java.util.Properties;
  7. @Configuration
  8. public class ImageVerifyCodeConfig {
  9. @Bean(name="captchaProducer")
  10. public DefaultKaptcha getKaptchaBean(){
  11. DefaultKaptcha defaultKaptcha=new DefaultKaptcha();
  12. Properties properties=new Properties();
  13. properties.setProperty("kaptcha.border", "yes");
  14. properties.setProperty("kaptcha.border.color", "105,179,90");
  15. properties.setProperty("kaptcha.textproducer.font.color", "blue");
  16. properties.setProperty("kaptcha.image.width", "125");
  17. properties.setProperty("kaptcha.image.height", "45");
  18. properties.setProperty("kaptcha.session.key", "code");
  19. properties.setProperty("kaptcha.textproducer.char.length", "4");
  20. properties.setProperty("kaptcha.textproducer.font.names", "宋体,楷体,微软雅黑");
  21. Config config=new Config(properties);
  22. defaultKaptcha.setConfig(config);
  23. return defaultKaptcha;
  24. }
  25. }