You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

同一项目配置ollama与openai模型时@Primary无法生效问题

多模型共存时@Primary配置失效问题

Bug描述

在同一项目中同时使用Ollama与OpenAI模型时,无法通过@Primary进行配置。

错误信息如下:

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 1 of method chatClientBuilder in org.springframework.ai.autoconfigure.chat.client.ChatClientAutoConfiguration required a single bean, but 2 were found:
    - ollamaChatModel: defined by method 'ollamaChatModel' in class path resource [org/springframework/ai/autoconfigure/ollama/OllamaAutoConfiguration.class]
    - openAiChatModel: defined by method 'openAiChatModel' in class path resource [org/springframework/ai/autoconfigure/openai/OpenAiAutoConfiguration.class]

This may be due to missing parameter name information

Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

Ensure that your compiler is configured to use the '-parameters' flag.
You may need to update both your build tool settings as well as your IDE.

环境依赖

<!-- spring boot AI -->
<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-openai-spring-boot-starter</artifactId>
    <version>1.0.0-M1</version>
</dependency>

<!--spring-ai-ollama-spring-boot-starter-->
<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-ollama-spring-boot-starter</artifactId>
    <version>1.0.0-M1</version>
</dependency>

复现步骤

@Autowired(required = false)
@Qualifier("openAiChatModel")
private ChatModel chatModel;

@Resource
@Qualifier("ollamaChatModel")
OllamaChatModel ollamaChatModel;

预期行为

支持在同一项目中同时使用Ollama、OpenAI等多模型,并可通过@Primary指定优先级。


内容的提问来源于stack exchange,提问作者CloudNativeLab

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 15:02:35