Springboot配置多数据源事务管理出错

本文探讨了在SpringBoot项目中配置多数据源时出现的错误:Parameter0 of method sqlSessionTemplate required a single bean but found multiple beans. 分析了可能的原因,包括不当使用@Primary注解及在@ConfigurationProperties前误用@Component。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Parameter 0 of method sqlSessionTemplate in org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration required a single bean, but 2 were found:

Consider marking one of the beans as @Primary, updating the consumer to acce

这个原因是在springboot配置多数据源的时候,可能在某个datasource1中配置了@Primary(主要注解),此时在你的datasource2中也去配置了这个注解,name这个问题就会产生

或者是当你在某个DBconfig中在配置注解@ConfigurationProperties(“mysql.datasource.db1”)在这个注解之前去配置了@Component这个组件注解,同样也会引起报错

==============================================
报错信息
Parameter 0 of method sqlSessionTemplate in org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration required a single bean, but 2 were found:
Consider marking one of the beans as @Primary, updating the consumer to acce……

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值