使用 Spring AI 1.0.0-SNAPSHOT:重要變更與更新

工程 | Mark Pollack | 2025 年 3 月 25 日 | ...

使用 Spring AI 1.0.0-SNAPSHOT:重要變更與更新

Spring AI 1.0.0-SNAPSHOT 對 artifact ID、依賴管理和自動配置引入了多項重要變更。這篇博文概述了這些變更,並提供瞭如何更新專案的指南。

最顯著的變更是 Spring AI starter artifact 的命名模式

  • 模型 starter:spring-ai-{model}-spring-boot-starterspring-ai-starter-model-{model}
  • 向量儲存 starter:spring-ai-{store}-store-spring-boot-starterspring-ai-starter-vector-store-{store}
  • MCP starter:spring-ai-mcp-{type}-spring-boot-starterspring-ai-starter-mcp-{type}

此外,您還需要新增 snapshot 倉庫並更新您的依賴管理配置。

有兩種方式將您的專案更新到 Spring AI 1.0.0-SNAPSHOT:使用 AI 工具自動更新手動更新。自動方式利用 Claude Code 快速轉換您的專案,而手動方式則為那些喜歡直接更改的使用者提供了分步說明。

使用 Claude Code 自動更新

對於喜歡自動化方式的使用者,您可以使用 Claude Code CLI 工具並提供提示,自動將您的專案升級到 1.0.0-SNAPSHOT。這種方法可以節省時間,減少升級多個專案或複雜程式碼庫時的錯誤。更多詳情,請參閱升級說明中的使用 AI 自動化升級部分。

這裡我們將透過螢幕截圖的形式展示 Claude Code CLI 工具將執行的步驟。

貼上提示。

Pasting a prompt in Claude

更新 BOM 版本。

Updating BOM version in Claude

新增倉庫。

Adding a repository in Claude

更新 starter。

Updating a starter in Claude

全部完成!

Task completion in Claude

手動更新

新增 Snapshot 倉庫

要使用 1.0.0-SNAPSHOT 版本,您需要將 snapshot 倉庫新增到您的構建檔案中。特別是需要依賴 Central Sonatype Snapshots 倉庫(https://central.sonatype.com/repository/maven-snapshots/)來獲取 MCP Java SDK 的 snapshot 依賴。

Maven

<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>

Gradle

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

Maven

<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>

Gradle

dependencies {
  implementation platform("org.springframework.ai:spring-ai-bom:1.0.0-SNAPSHOT")
  // Add specific Spring AI dependencies here
}

Spring AI Artifact ID 的變更

Spring AI starter artifact 的命名模式在 1.0.0-SNAPSHOT 中發生了變化。您需要根據以下模式更新您的依賴項

  • 模型 starter:spring-ai-{model}-spring-boot-starterspring-ai-starter-model-{model}
  • 向量儲存 starter:spring-ai-{store}-store-spring-boot-starterspring-ai-starter-vector-store-{store}
  • MCP starter:spring-ai-mcp-{type}-spring-boot-starterspring-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 的變更

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}
  • MCP 自動配置:spring-ai-autoconfigure-mcp-{type}

在大多數情況下,您不需要顯式新增這些自動配置依賴項。當您使用相應的 starter 依賴項時,它們會被傳遞性地包含在內。

獲取 Spring 新聞郵件

訂閱 Spring 新聞郵件,保持連線

訂閱

先行一步

VMware 提供培訓和認證,助您加速前進。

瞭解更多

獲得支援

Tanzu Spring 在一個簡單的訂閱中提供對 OpenJDK™、Spring 和 Apache Tomcat® 的支援和二進位制檔案。

瞭解更多

近期活動

檢視 Spring 社群所有即將舉行的活動。

檢視全部