spring-ai 下载不了依赖spring-ai-openai-spring-boot-starter

第1坑:配置第三方仓库不生效, 提示在阿里云仓库没有找到 spring-ai-openai-spring-boot-starter

第2坑:升级jdk17后,springboot项目启动报错

Internal error (java.lang.reflect.InaccessibleObjectException): Unable to make protected void java.util.ResourceBundle.setParent(java.util.ResourceBundle) accessible: module java.base does not "opens java.util" to unnamed module @bef2d72

java.lang.reflect.InaccessibleObjectException: Unable to make protected void java.util.ResourceBundle.setParent(java.util...

也可以尝试多次运行,一般第二次就会成功运行,原因不详!!! 本人尝试配置vm参数好像不会再出现这个情况,尝试的少,所以不好定论

3. 中间商

https://api.xty.app/token

4.application.properties配置

附上完整的pom文件:

复制代码
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <groupId>com.ldj.ai</groupId>
    <artifactId>open-ai</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>open-ai</name>
    <description>openAI project for Spring Boot</description>

    <properties>
        <java.version>17</java.version>
        <spring-ai.version>1.0.0-M1</spring-ai.version>
    </properties>

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

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <artifactId>junit-jupiter</artifactId>
                    <groupId>org.junit.jupiter</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        
        <!--单测有点小bug,说找不到依赖,降低junit版本-->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.5.0</version>
            <scope>test</scope>
        </dependency>

        <!--版本继承spring-ai-bom-->
        <dependency>
            <groupId>org.springframework.ai</groupId>
            <artifactId>spring-ai-openai-spring-boot-starter</artifactId>
        </dependency>
    </dependencies>

    <!--第三方依赖库,注意配置了有可能不生效,需要修改maven setting配置文件,见截图-->
    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

参考官方示例:Chat Client API :: Spring AI Reference

后续补充:

复制代码
package com.ldj.ai.openai.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.*;

/**
 * User: ldj
 * Date: 2024/7/7
 * Time: 15:03
 * Description: AI 聊天controller
 */
@RestController
@RequestMapping("/openai")
public class ChatController {

    private final ChatClient chatClient;

    public ChatController(ChatClient.Builder chatClientBuilder) {
        this.chatClient = chatClientBuilder.build();
    }

    @GetMapping("/chat")
    public String generation(@RequestParam(value = "question", defaultValue = "使用中文简短介绍自己") String question) {
        return this.chatClient.prompt()
                .user(question)
                .call()
                .content();
    }

}
相关推荐
武子康3 分钟前
Seedream 5.0 Pro 进入 Vercel AI Gateway:图像生成开始网关化
人工智能·ai·chatgpt·gateway·agent·claude·harness
能源科技集6 分钟前
GWh时代储能逻辑生变,远景动力(AESC)790Ah电芯反向定义系统最优解
人工智能
Forerror20267 分钟前
API网关怎么部署?MAI Gateway配置教程与最佳实践
人工智能·gateway·maigateway·finapi·企业级ai网关·大模型财务管控
2601_962100739 分钟前
AI批量生成视频的工程化复盘(2026):一条能断点续跑、不重复扣量的出片脚本
人工智能·音视频
qq_4255161815 分钟前
双语字幕会议记录APP:多语言会议整理工具推荐
人工智能·智能手机·语音识别
xian_wwq18 分钟前
【学习笔记】-深度认知系列-第8讲主流AI模型横向评测——GPT、Claude、Gemini、盘古、文心、通义
人工智能·笔记·学习
面包狗AI4S19 分钟前
Codex/ChatGPT 反复 Reconnecting(正在重新连接) 5/5 的最简修复方法
人工智能·vscode·chatgpt
小柯南敲键盘20 分钟前
跨境电商批量图片翻译与视频字幕翻译,就用跨马AI工具
大数据·人工智能·python·音视频
嘿嘿-6621 分钟前
Cherry Studio 接入ChatGpt:GPT-5.6 Sol 文本测试与 GPT-Image-2 出图教程
人工智能·gpt·ai·chatgpt·node.js·ai编程
hiahiahia12321 分钟前
HTTP Streaming:为什么 AI 回答经常要边生成边返回?
人工智能·网络协议·http