解决在父级pom文件中使用spring-ai-bom统一管理版本下导入spring-ai-openai-spring-boot-starter依赖出现报错的问题

解决在父级pom文件中使用spring-ai-bom统一管理版本下导入spring-ai-openai-spring-boot-starter依赖出现报错的问题

1. 引入spring ai的依赖

通常我们如果想要在 Spring Boot项目里简单地接入 OpenAI 系列模型,我们会引入Spring AI官方提供的OpenAI集成Starter:

1
2
3
4
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-openai-spring-boot-starter</artifactId>
</dependency>

2. spring-ai-bom

如果我们引入了很多spring ai相关的依赖,我们通常会使用spring-ai-bom进行版本管理

1
2
3
4
5
6
7
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-bom</artifactId>
<version>1.0.0-M8</version>
<type>pom</type>
<scope>import</scope>
</dependency>

spring-ai-bom指明所有spring-ai相关的依赖都在1.0.0-M8这个版本下。

3. maven编译的时候,于是就出现了以下报错:

1
2
3
org.springframework.ai:spring-ai-openai-spring-boot-starter:jar:unknown was not found in http://maven.aliyun.com/nexus/content/groups/public/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of alimaven has elapsed or updates are forced

Try to run Maven import with -U flag (force update snapshots)

这个错误表示无法下载对应的spring-ai-openai-spring-boot-starter依赖。。。。

4. 解决方案

  1. 删除spring-ai-openai-spring-boot-starter
  2. 添加引入spring-ai-starter-model-openai这个依赖
1
2
3
4
5
6
7
8
9
10
<!--        <dependency>-->
<!-- <groupId>org.springframework.ai</groupId>-->
<!-- <artifactId>spring-ai-openai-spring-boot-starter</artifactId>-->
<!-- </dependency>-->

<!-- Spring AI OpenAI Starter -->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-openai</artifactId>
</dependency>

再重新编译就成功了。

5. 原因

1.0.0-M8 Spring AI starter artifact 的命名模式已更改

  • spring-ai-openai-spring-boot-starter 在M8已被官方删除,在M8版本下使用它当然下载不到。
  • 正确的依赖名称是 spring-ai-starter-model-openai
1
2
3
4
5
6
7
8
9
10
11
<!-- BEFORE -->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-openai-spring-boot-starter</artifactId>
</dependency>

<!-- AFTER -->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-openai</artifactId>
</dependency>

END