首先在我们建好的项目的pom.xml文件中添加Spring的里程碑和快照存储库
添加Spring AI的依赖管理
Spring AI 物料清单 (BOM) 声明了给定 Spring AI 版本使用的所有依赖项的推荐版本。从应用程序的构建脚本使用 BOM 可以避免您自己指定和维护依赖项版本的需求。相反,您使用的 BOM 版本决定了使用的依赖项版本。它还确保默认情况下使用受支持和经过测试的依赖项版本,除非您选择覆盖它们。
添加Spring AI Ollama特定组件的依赖项
修改application.yml配置,添加以下内容
在添加好配置后运行项目一直报错,在整个修改尝试的过程中遇到了两种错误:
一种是加载依赖时报错:
org.springframework.ai:spring-ai-ollama-spring-boot-starter:jar:unknown was not found in https://repo.spring.io/milestone during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of spring-milestones has elapsed or updates are forced
一种是运行时报错:
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
……
java.lang.IllegalStateException: Error processing condition on org.springframework.ai.autoconfigure.ollama.OllamaAutoConfiguration.ollamaApi
……
这之后我尝试了依赖版本降级、springboot版本升级等方法,最后认为是依赖版本冲突的问题
在多次尝试后,目前我可用的springboot版本及spring ai依赖版本如下: