spring有多个对象时如何注入

java 复制代码
@Bean
	public ReactAgent chatbotReactAgent(ChatModel chatModel,
			ShellTool2 shellTool,
			ToolCallback executePythonCode,
			ToolCallback viewTextFile,
			MemorySaver memorySaver) {
		return xxx;

这个里面有两个ToolCallback,如何注入

java 复制代码
@Bean
	public ToolCallback executePythonCode() {
		return FunctionToolCallback.builder("execute_python_code", new PythonTool())
				.description(PythonTool.DESCRIPTION)
				.inputType(PythonTool.PythonRequest.class)
				.build();
	}

	// 把框架提供的 ReadFileTool 包装成名为 view_text_file 的读文件工具。
	@Bean
	public ToolCallback viewTextFile() {
		ReadFileTool readFileTool = new ReadFileTool();
		return FunctionToolCallback.builder("view_text_file", readFileTool)
				.description("View the contents of a text file. The file_path parameter must be an absolute path. " +
						"You can specify offset and limit to read specific portions of the file. " +
						"By default, reads up to 500 lines starting from the beginning of the file.")
				.inputType(ReadFileTool.ReadFileRequest.class)
				.build();
	}

spring对象注入

1.先按类型找;

2.如果同类型有多个,再按 Bean 名区分,默认函数名就是Bean的名字,也可以指定;

java 复制代码
@Bean("pythonToolCallback")
public ToolCallback executePythonCode() {
    return FunctionToolCallback.builder("execute_python_code", new PythonTool())
            .description(PythonTool.DESCRIPTION)
            .inputType(PythonTool.PythonRequest.class)
            .build();
}

3.如果还分不清,就用 @Qualifier 明确指定。

java 复制代码
@Qualifier("pythonToolCallback") ToolCallback executePythonCode
相关推荐
西门吹-禅5 小时前
java springboot N+1问题
java·开发语言·spring boot
DLYSB_6 小时前
生命通道:如何用 HIS 医疗系统直连网络声光终端,打造“零延误”的危急值响应网关?
java·网络·数据库·报警灯
weixin_BYSJ19876 小时前
SpringBoot + MySQL 乒乓球运动员信息管理系统项目实战--附源码04954
java·javascript·spring boot·python·django·flask·php
AI小码6 小时前
LLM 应用的缓存工程:当每次 API 调用都在燃烧成本
java·人工智能·spring·计算机·llm·编程·api
犀利豆7 小时前
AI in Harness(四)
人工智能·后端
Hui Baby7 小时前
Spring Security
java·后端·spring
IT笔记7 小时前
【Rust】Rust Match 模式匹配详解
java·开发语言·rust
逝水无殇8 小时前
C# 运算符重载详解
开发语言·后端·c#
我才是银古8 小时前
构建 Java GIS 工具库:从碎片化 API 到统一抽象的设计实践
java·gis·geotools·gdal·esri
苏三说技术8 小时前
2026编程圈很火的10个Skills
后端