惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
量子位
腾讯CDC
A
About on SuperTechFans
小众软件
小众软件
Microsoft Azure Blog
Microsoft Azure Blog
T
Tailwind CSS Blog
V
V2EX
B
Blog RSS Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
GbyAI
GbyAI
Recent Announcements
Recent Announcements
Microsoft Security Blog
Microsoft Security Blog
博客园 - 叶小钗
罗磊的独立博客
宝玉的分享
宝玉的分享
WordPress大学
WordPress大学
大猫的无限游戏
大猫的无限游戏
IT之家
IT之家
V
Visual Studio Blog
D
DataBreaches.Net
博客园 - 三生石上(FineUI控件)
月光博客
月光博客
有赞技术团队
有赞技术团队

博客园 - cn2025

K8s -sentinel-dashboard【nacos版本】集 20260815 kubeSphere【ks-controller-manager-webhook-cert】证书 20260814 K8s -nacos集 20260813 K8s - 安装部署redis集群-哨兵sentinels集(支持从K8s外部访问)20260812 k8s-deployment发布测试(pv-pvc-deployment-service) 20260810 K8s - 安装部署Kafka、Zookeeper集群教程(支持从K8s外部访问)20260808 k8s-关机及启动脚本工具 【kubeSphere发布ruoyi-pro前端】工具脚本20260731 【k8s】 etcd服务端及客户端版本及快照【定时】备份 20260730 harbor【https启用】及k8节点部证书20260728 kube-flannel.yml k8s集群-安装helm 【kubeShpere】 官网 20260710 kubesphere-KDP 工具脚本【kubeSphere发布ruoyi-pro前端】20260720 HbuilderX 内置终端转为 gitBash 20260720 kubeSphere发布ruoyi-pro后端-用到脚本 kubeSphere发布ruoyi-web前端 20260711 kubeSphere发布ruoyi-pro后端 k8s集群-kubeShpere 20260710 安装Helm 20260710 k8s-portainer docker 镜像查询 k8集群一键重置 docker run OceanBase spring ai alibaba doc AI2.0 【多模态】 20260615 世界只有一个墨脱 AI2.0 【Mcp-client】 20260611 AI2.0 【Mcp-server】 20260611 GoLand 配Go SDK
AI2.0 dashscope-openai 20260527
cn2025 · 2026-05-27 · via 博客园 - cn2025

image

1、pom

<properties>
<java.version>17</java.version>
<spring-ai.version>2.0.0-M7</spring-ai.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-openai</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webmvc-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-bom</artifactId>
<version>${spring-ai.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

2、application.yml

${OPENAI_API_KEY}

image

spring:
application:
name: dashscope18088
ai:
openai:
api-key: ${OPENAI_API_KEY}
base-url: https://dashscope.aliyuncs.com/compatible-mode/v1
chat:
model: qwen3.6-plus
# chat:
# model: qwen3.6-plus
# 可选:超时/重试配置
# options:
# temperature: 0.7
# max-tokens: 2000
server:
port: 18088

3、config

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AiConfiguration {

@Bean
public ChatClient chatClient(OpenAiChatModel model){
return ChatClient
.builder(model) // 绑定OpenAiChatModel模型
.build(); // 构建ChatClient实例
}
}

4、controller

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MyAiChatController {

@Autowired
private ChatClient chatClient;

@RequestMapping("/ai")
public String ai(String question){
return chatClient.prompt() // 创建 Prompt 对象,用于构建聊天请求
.user(question) // 设置用户输入
.call() // 调用模型,返回结果
.content(); // 获取结果内容
}
}

5、访问

http://localhost:18088/ai?question=你是谁?

image