# 集成指南
- 前提条件,项目已经升级到java17,spring6.x,springboot3.x;
- 编译及运行功能均正常使用;
# 添加依赖(集成zhipuAI为例)
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-bom</artifactId>
<version>1.1.4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-zhipuai</artifactId>
</dependency>
</dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
# 配置api
spring:
ai:
zhipuai:
api-key: <your api key>
# controller配置类测试
package com.automannn.natm.ai;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Author: automannn
* DateTime: 2026/4/3 14:42
* Description:
*/
@RestController
@RequestMapping("/ai-test")
public class AiTestController {
private final ChatClient chatClient;
//默认情况下,Spring AI 会自动配置一个单个的 ChatClient.Builder bean
//通过 spring.ai.chat.client.enabled=false 可以禁用ChatClient.Builder的自动配置
public AiTestController(ChatClient.Builder builder) {
this.chatClient = builder.build();
}
@GetMapping("/ask")
String generation(String userInput) {
return this.chatClient.prompt()
.user(userInput)
.call()
.content();
}
}
