惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
O
OpenAI News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
Webroot Blog
Webroot Blog
GbyAI
GbyAI
S
SegmentFault 最新的问题
Cyberwarzone
Cyberwarzone
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
J
Java Code Geeks
Google DeepMind News
Google DeepMind News
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
博客园 - 【当耐特】
S
Secure Thoughts
酷 壳 – CoolShell
酷 壳 – CoolShell
AWS News Blog
AWS News Blog
Engineering at Meta
Engineering at Meta
S
Security Affairs
H
Help Net Security
Microsoft Security Blog
Microsoft Security Blog
D
DataBreaches.Net
云风的 BLOG
云风的 BLOG
Hugging Face - Blog
Hugging Face - Blog
Google DeepMind News
Google DeepMind News
Spread Privacy
Spread Privacy
T
Threatpost
Forbes - Security
Forbes - Security
C
Cisco Blogs
Scott Helme
Scott Helme
Attack and Defense Labs
Attack and Defense Labs
Simon Willison's Weblog
Simon Willison's Weblog
腾讯CDC
The Last Watchdog
The Last Watchdog
Cloudbric
Cloudbric
Last Week in AI
Last Week in AI
Recorded Future
Recorded Future
小众软件
小众软件
V
Vulnerabilities – Threatpost
美团技术团队
人人都是产品经理
人人都是产品经理
有赞技术团队
有赞技术团队
Apple Machine Learning Research
Apple Machine Learning Research
Hacker News - Newest:
Hacker News - Newest: "LLM"
I
Intezer
月光博客
月光博客
C
Cyber Attacks, Cyber Crime and Cyber Security
博客园 - 司徒正美
C
Cybersecurity and Infrastructure Security Agency CISA
Martin Fowler
Martin Fowler
博客园 - 聂微东

博客园 - CharyGao

OpenAI Codex AI降智解决方案, 原因解析与系统提示词修改指南 OpenClaw vs Coze/Dify/n8n 帮你半小时内选对合适的AI Skills 热潮过去后,我重新理解了 AI Agent 的方向 智读致用|《埃隆之书》 《一人企业》 一人公司:The Agency 免费“雇佣“144个AI专家,虚拟团队走进现实 用微软Agent Framework打造智能博客生成系统+AI智能体军团 告别加班(第二期):月报还是Word排版?本地AI解您愁 居然可以在 Claude 桌面端用三方模型了! Claude Code 每次启动都要确认权限?一行配置永久解决 98.5% 的人都不知道:SSH 居然还有个“隐藏菜单” 强程序员在 AI 时代的赚钱路径 骚操作来了!Claude编程的42个实战技巧大全 面试官:“简历写着熟练使用 Claude Code,连 simplify 代码审查命令都不知道!”,我:“那又如何呢?” SpringBoot+ResponseBodyEmitter异步流式推送神技 加密后的数据如何进行模糊查询? 最适合新手安装的10个小龙虾🦞 skills来了! 周末和孩子必看的亲子电影合集,陪伴孩子成长的每一步 拒绝代码泄露与“屎山”迷航:GitNexus纯本地知识图谱+可视化关系网,引发GitHub 8800星狂欢 还原BatchEncryption(201610版本)混淆的批处理文件 用上这个Skill,你的Claude Code/Codex 将会比别人快5倍 -- 用分布式思维驯服AI任务编排 前端项目中定义vs code要安装的插件 vscode中claude code插件代理地址设置 2026新手必学:GPT-5.5高效提示词指南 解决 URLEncoder.encode 编码空格变 + 号 HTTP 与 SpringBoot 参数提交与接收协议方式 SpringBoot多线程池配置 springboot使用logback自定义日志 SpringBoot + Cursor 最佳提示词工程手册 scoop国内安装方法 Prompt 工程实战总结:文本分类、信息抽取、语义匹配 PowerShell DSC(Desired State Configuration)实战指南 OpenResty Lua 代码断点 调试指南:VSCode + LuaPanda OpenClaw多智能体路由实战:飞书多机器人配置指南 OpenClaw 提示词全集 (Prompt Collection) n8n 2.0 中文汉化版一键部署教程 | 解除Execute Command限制 java中Redisson ,jedis,Lettuce和Spring Data Redis的四种深度对比和优缺点详解 Java Web 技术演进:Servlet → Spring → Spring Boot Everything Claude Code(Anthropic 黑客松冠军开源配置) 从 ChatGPT 到 Coding Agent:AI 执行时代的未来猜想 【万字长文】Gemini 3 Pro 全面指南:从免费订阅到 CLI / Agent 实战 Codex 全面实战教程:从安装到工程协作,一篇跑通 3万字硬核拆解 Claude Code:从入门到工程化落地 Gemini 3 完整指南 Codex 完整指南 Claude Code 完整指南4-10 Claude Code 完整指南 claude code 自动保存对话插件 提示词99+ 拜拜Cursor,你好Kiro!(附全平台安装包下载,Win、Mac、Linux) 别再忍了!uv 下载慢如龟速?一招配置国内镜像,让你的 Python 体验坐上火箭! docker配置参数详解---/etc/docker/daemon.json完整参数 win11 清理 OpenCowork 让 AI 在飞书里真正「动手干活」 教你从0到1安装OpenClaw,快速接入飞书,打通任督二脉! SpringBoot 最大连接数及最大并发数是多少??? SpringBoot vs Nginx:5种实现vs1个指令,谁才是防盗链的“真·王者”? Spring Boot日志集成 Redisson 使用手册:从 API 误区到看门狗失效,在此终结分布式锁的噩梦 OpenClaw超级速查表 zeroclaw ubunut25 -ARM 修改国内镜像 openClaw国内镜像安装 知识图谱 —— 结构化知识的强大工具 什么是 Supervised learning(监督学习) 机器学习中的过拟合与欠拟合现象:理论与实践案例研究 解析 Anthropic 的模型上下文协议(MCP)及其优点
Springboot通过谷歌Kaptcha 组件,生成图形验证码
charygao1990 · 2026-05-06 · via 博客园 - CharyGao

教程

图形验证码属于老生常谈了,具体细节这里就不说了。生成图形验证码的办法非常多,今天讲解一种通过Kaptcha组件快速生成图形验证码的方法。
Kaptcha是谷歌开源的一款简单实用的图形验证码组件。我个人推荐它的最大原因是容易上手,采用约定大于配置的方式,快速契合到项目中。
话不多说,我们看看该如何使用它:

 
  1. <groupId>com.google.code.kaptcha</groupId>

  2. <artifactId>kaptcha</artifactId>

 
 
  1. public class KaptchaConfig {

  2. public DefaultKaptcha getDefaultKaptcha(){

  3. com.google.code.kaptcha.impl.DefaultKaptcha defaultKaptcha = new com.google.code.kaptcha.impl.DefaultKaptcha();

  4. Properties properties = new Properties();

  5. properties.put("kaptcha.border", "no");

  6. properties.put("kaptcha.textproducer.font.color", "red");

  7. properties.put("kaptcha.image.width", "213");

  8. properties.put("kaptcha.image.height", "88");

  9. properties.put("kaptcha.textproducer.font.size", "45");

  10. properties.put("kaptcha.session.key", "verifyCode");

  11. properties.put("kaptcha.textproducer.char.space", "6");

  12. properties.put("kaptcha.obscurificator.impl", "com.google.code.kaptcha.impl.WaterRipple");

  13. properties.put("kaptcha.background.clear.from", "yellow");

  14. properties.put("kaptcha.background.clear.to", "green");

  15. Config config = new Config(properties);

  16. defaultKaptcha.setConfig(config);

 
配置名 配置作用 默认值
kaptcha.border 图片边框,合法值:yes , no yes
kaptcha.border.color 边框颜色,合法值: r,g,b (and optional alpha) 或者 white,black,blue. black
kaptcha.image.width 图片宽 200
kaptcha.image.height 图片高 50
kaptcha.producer.impl 图片实现类 com.google.code.kaptcha.impl.DefaultKaptcha
kaptcha.textproducer.impl 文本实现类 com.google.code.kaptcha.text.impl.DefaultTextCreator
kaptcha.textproducer.char.string 文本集合,验证码值从此集合中获取 abcde2345678gfynmnpwx
kaptcha.textproducer.char.length 验证码长度 5
kaptcha.textproducer.font.names 字体 Arial, Courier
kaptcha.textproducer.font.size 字体大小 40px.
kaptcha.textproducer.font.color 字体颜色,合法值: r,g,b 或者 white,black,blue. black
kaptcha.textproducer.char.space 文字间隔 2
kaptcha.noise.impl 干扰实现类 com.google.code.kaptcha.impl.DefaultNoise
kaptcha.noise.color 干扰 颜色,合法值: r,g,b 或者 white,black,blue. black
kaptcha.obscurificator.impl

图片样式:<br />水纹 com.google.code.kaptcha.impl.WaterRipple <br />

鱼眼 com.google.code.kaptcha.impl.FishEyeGimpy <br />

阴影 com.google.code.kaptcha.impl.ShadowGimpy

com.google.code.kaptcha.impl.WaterRipple
kaptcha.background.impl 背景实现类 com.google.code.kaptcha.impl.DefaultBackground
kaptcha.background.clear.from 背景颜色渐变,开始颜色 light grey
kaptcha.background.clear.to 背景颜色渐变, 结束颜色 white
kaptcha.word.impl 文字渲染器 com.google.code.kaptcha.text.impl.DefaultWordRenderer
kaptcha.session.key session key KAPTCHA_SESSION_KEY
kaptcha.session.date session date
 
  1. @GetMapping("/login/getVerifyCode")

  2. public void getVerifyCode(String loginKey,

  3. HttpServletRequest httpServletRequest,

  4. HttpServletResponse httpServletResponse) {

  5. log.warn("query verify Code" + loginKey);

  6. loadService.getVerifyCode(loginKey, httpServletRequest, httpServletResponse);

  7. log.error("get verify Code failed :", e);

 
 
  1. public void getVerifyCode(String loginKey, HttpServletRequest httpServletRequest,

  2. HttpServletResponse httpServletResponse) throws IOException {

  3. ByteArrayOutputStream imgOutputStream = new ByteArrayOutputStream();

  4. String verifyCode = captchaProducer.createText();

  5. captchaMap.put(loginKey, verifyCode);

  6. log.warn("reset verify code key {}, code {}", loginKey, verifyCode);

  7. BufferedImage challenge = captchaProducer.createImage(verifyCode);

  8. ImageIO.write(challenge, "jpg", imgOutputStream);

  9. } catch (IllegalArgumentException | IOException e) {

  10. httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND);

  11. byte[] captchaOutputStream = imgOutputStream.toByteArray();

  12. httpServletResponse.setHeader("Cache-Control", "no-store");

  13. httpServletResponse.setHeader("Pragma", "no-cache");

  14. httpServletResponse.setDateHeader("Expires", 0);

  15. httpServletResponse.setContentType("image/jpeg");

  16. try (ServletOutputStream responseOutputStream = httpServletResponse.getOutputStream()) {

  17. responseOutputStream.write(captchaOutputStream);

  18. responseOutputStream.flush();

  19. } catch (IOException ex) {

  20. log.error("find ex in create a new verify Code", ex);