SpringBoot+Mybatis多数据源配置遇到的小问题,qualifying bean of type 'javax.sql.DataSource' available: more than o

之前开发的过程中,SpringBoot+Mybatis对数据读写分离时,遇到多数据源时SpringBoot无法配置的问题,总结一下:

报错1

No qualifying bean of type 'javax.sql.DataSource' available: more than one 'primary' bean found among candidates: [baseDB, scoreDb]

这个错误是因为SpringBoot在加载多数据源配置的过程中无法确定哪一个是主数据源,可以通过以下方法解决

1、在SpringBoot的启动配置中,排除掉SpringBoot的数据源自动配置

2、将多数据源中的一个数据源指定为主数据源@Primary

报错2:invalid bound statement (not found)

这个错误是Mybatis的关系映射数据绑定出现错误,主要是从以下方面来处理

1、配置文件路径错误,从而导致无法正确加载配置

2、有没有正确的扫描dao层的mapper

3、xml文件的dao引用和方法名有没有错误

发布了117 篇原创文章 · 获赞 17 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/Jack__iT/article/details/101623733