先行一步
VMware 提供培训和认证,助您加速前进。
了解更多Spring AI 1.0.0-SNAPSHOT 对 artifact ID、依赖管理和自动配置引入了多项重要变更。这篇博文概述了这些变更,并提供了如何更新项目的指南。
最显著的变更是 Spring AI starter artifact 的命名模式
spring-ai-{model}-spring-boot-starter
→ spring-ai-starter-model-{model}
spring-ai-{store}-store-spring-boot-starter
→ spring-ai-starter-vector-store-{store}
spring-ai-mcp-{type}-spring-boot-starter
→ spring-ai-starter-mcp-{type}
此外,您还需要添加 snapshot 仓库并更新您的依赖管理配置。
有两种方式将您的项目更新到 Spring AI 1.0.0-SNAPSHOT:使用 AI 工具自动更新或手动更新。自动方式利用 Claude Code 快速转换您的项目,而手动方式则为那些喜欢直接更改的用户提供了分步说明。
对于喜欢自动化方式的用户,您可以使用 Claude Code CLI 工具并提供提示,自动将您的项目升级到 1.0.0-SNAPSHOT。这种方法可以节省时间,减少升级多个项目或复杂代码库时的错误。更多详情,请参阅升级说明中的使用 AI 自动化升级部分。
这里我们将通过屏幕截图的形式展示 Claude Code CLI 工具将执行的步骤。
粘贴提示。
更新 BOM 版本。
添加仓库。
更新 starter。
全部完成!
要使用 1.0.0-SNAPSHOT 版本,您需要将 snapshot 仓库添加到您的构建文件中。特别是需要依赖 Central Sonatype Snapshots 仓库(https://central.sonatype.com/repository/maven-snapshots/
)来获取 MCP Java SDK 的 snapshot 依赖。
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<releases>
<enabled>false</enabled>
</releases>
</repository>
<repository>
<name>Central Portal Snapshots</name>
<id>central-portal-snapshots</id>
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/snapshot' }
maven {
name = 'Central Portal Snapshots'
url = 'https://central.sonatype.com/repository/maven-snapshots/'
}
}
在您的构建配置中将 Spring AI BOM 版本更新到 1.0.0-SNAPSHOT
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-bom</artifactId>
<version>1.0.0-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
dependencies {
implementation platform("org.springframework.ai:spring-ai-bom:1.0.0-SNAPSHOT")
// Add specific Spring AI dependencies here
}
Spring AI starter artifact 的命名模式在 1.0.0-SNAPSHOT 中发生了变化。您需要根据以下模式更新您的依赖项
spring-ai-{model}-spring-boot-starter
→ spring-ai-starter-model-{model}
spring-ai-{store}-store-spring-boot-starter
→ spring-ai-starter-vector-store-{store}
spring-ai-mcp-{type}-spring-boot-starter
→ spring-ai-starter-mcp-{type}
之前
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-openai-spring-boot-starter</artifactId>
</dependency>
之后
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-openai</artifactId>
</dependency>
Spring AI 自动配置已从单一的整体 artifact 变更为按模型、向量存储及其他组件划分的独立自动配置 artifact。这一变更是为了最大程度地减少不同版本依赖库(如 Google Protocol Buffers, Google RPC 等)冲突的影响。
通过将自动配置分离到组件特定的 artifact 中,您可以避免引入不必要的依赖项,并降低应用程序中版本冲突的风险。
原始的整体 artifact 已不再可用
<!-- NO LONGER AVAILABLE -->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-spring-boot-autoconfigure</artifactId>
<version>${project.version}</version>
</dependency>
取而代之的是,每个组件现在都有自己的遵循以下模式的自动配置 artifact
spring-ai-autoconfigure-model-{model}
spring-ai-autoconfigure-vector-store-{store}
spring-ai-autoconfigure-mcp-{type}
在大多数情况下,您不需要显式添加这些自动配置依赖项。当您使用相应的 starter 依赖项时,它们会被传递性地包含在内。