发布日期:2026-03-26 版本:Spring AI 2.0.0-M4 / 1.1.4 / 1.0.5
一、版本概览
Spring AI 团队同时发布了三个版本:
| 版本 | 定位 | 改进数 |
|---|---|---|
| 2.0.0-M4 | 下一代里程碑版本 | 28项改进 |
| 1.1.4 | 当前稳定版 | 13项改进 |
| 1.0.5 | LTS维护版 | 10项改进 |
总计:51项改进、bug修复和文档更新。
二、⚠️ 重要变更:三大模型集成将弃用
受影响的集成
| 集成 | 状态 | 建议 |
|---|---|---|
| Vertex AI | 🚫 弃用 | 迁移到 OpenAI / Azure OpenAI |
| ZhiPu AI(智谱AI) | 🚫 弃用 | 迁移到 Anthropic / 其他 |
| OCI GenAI(Oracle Cloud) | 🚫 弃用 | 迁移到支持的提供商 |
时间线:这些集成类已在 2.0.0-M4 标记为 @Deprecated,将在未来的主要版本中完全移除。
为什么弃用?
官方未明确说明,但可能原因:
- 维护成本:部分集成使用率低
- API不稳定:提供商API变更频繁
- 功能重叠:主流模型已足够覆盖
三、2.0.0-M4 新特性详解
特性1:Gemini 3.x + Google Search 增强
现在可以在 Gemini 模型中使用 Google Search,同时结合自定义工具:
// 之前的限制:Google Search 与自定义工具不能同时使用
// 现在:可以同时启用
ChatResponse response = chatClient.prompt()
.user("搜索最新的 Spring AI 新闻并总结")
.functions("googleSearch", "myCustomTool") // 同时使用
.call()
.chatResponse();
应用场景:
- 搜索 + 本地数据库查询
- 搜索 + API调用
- 多源信息整合
特性2:动态禁用结构化输出
// 某些场景需要禁用原生结构化输出
ChatOptions options = ChatOptions.builder()
.withStructuredOutputEnabled(false) // 新增
.build();
为什么要禁用:
- 某些模型对结构化输出支持不完善
- 需要自定义输出格式时
- 调试和排查问题时
四、关键Bug修复
修复1:extraBody 配置丢失
问题描述:当指定 toolDefinitions 时,extraBody 配置会丢失。
// 之前:extraBody 被忽略
ChatOptions options = ChatOptions.builder()
.withToolDefinitions(tools)
.withExtraBody("custom_key", "value") // 丢失!
.build();
// 现在:已修复,extraBody 正确传递
修复2:Azure OpenAI stop 字段初始化
// 之前:stop 字段初始化失败
AzureOpenAiChatOptions options = AzureOpenAiChatOptions.builder()
.withStop(List.of("END")) // 可能报错
.build();
// 现在:已修复
修复3:Redis 向量存储过滤器
// 修复了 TAG 和 TEXT 过滤值的字符串处理
vectorStore.similaritySearch(
SearchRequest.query("test")
.withFilterExpression("tag == 'important'") // 现在正确工作
);
五、依赖升级
| 依赖 | 旧版本 | 新版本 |
|---|---|---|
| Google Generative AI SDK | - | 1.44.0 |
| OpenAI SDK | - | 4.28.0 |
| Anthropic SDK | - | 2.17.0 |
六、升级建议
如果你使用 1.x 版本
<!-- 升级到 1.1.4(推荐) -->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-core</artifactId>
<version>1.1.4</version>
</dependency>
如果你想尝试 2.0.0
<!-- 里程碑版本,谨慎使用 -->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-core</artifactId>
<version>2.0.0-M4</version>
</dependency>
<!-- 需要添加里程碑仓库 -->
<repositories>
<repository>
<id>spring-milestones</id>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
⚠️ 如果你使用被弃用的集成
立即行动:
// 迁移前:Vertex AI
ChatModel model = new VertexAiChatModel(...);
// 迁移后:OpenAI
ChatModel model = new OpenAiChatModel(...);
// 或 Azure OpenAI
ChatModel model = new AzureOpenAiChatModel(...);
七、坑点与注意事项
坑点1:弃用警告不会阻止编译
// 代码仍可编译,但运行时可能出问题
@Deprecated // 只有警告,没有错误
public class VertexAiChatModel { ... }
建议:在 IDE 中启用弃用警告,主动发现。
坑点2:2.0.0-M4 是里程碑版本
- 不推荐用于生产环境
- API 可能变更
- 文档可能不完整
坑点3:配置兼容性
# 1.x 配置格式
spring:
ai:
openai:
api-key: ${OPENAI_API_KEY}
# 2.0.0 配置格式(可能变化)
spring:
ai:
model:
openai:
api-key: ${OPENAI_API_KEY}
八、总结
| 问题 | 答案 |
|---|---|
| 是否需要升级? | 使用1.1.4即可,2.0.0-M4谨慎尝鲜 |
| 被弃用的集成怎么办? | 尽快迁移到OpenAI/Azure/Anthropic |
| 有安全修复吗? | 有,修复了CVE-2026-22738等 |
| 推荐版本? | 1.1.4(稳定)/ 1.0.5(LTS) |
参考资料
- Spring AI 2.0.0-M4 Release Notes
- Spring AI 1.1.4 Release Notes
- Spring AI 1.0.5 Release Notes
- Spring AI 官方文档
本文基于 Spring AI 2.0.0-M4 / 1.1.4 / 1.0.5 发布说明整理