配置多数据源required a single bean, but 2 were found:

file [D:\IdeaProjects\demo\target\classes\com\example\demo\test1\mapper\StudentMapper.class] required a single bean, but 2 were found:
- sqlSessionFactory1: defined by method ‘sqlSessionFactory1’ in class path resource [com/example/demo/config/MybatisDbAConfig.class]
- sqlSessionFactory2: defined by method ‘sqlSessionFactory2’ in class path resource [com/example/demo/config/MybatisDbBConfig.class]
这里是我在学习springboot配置多数据源碰到的问题

网上找的解决方法

链接: https://www.lovecto.cn/20180705/14.htmlps://mp.csdn.net).

图片: 配置多数据源required a single bean, but 2 were found:_第1张图片

自己的解决方法

我按照他的方法试了一下,不行,最后找到其他配置数据源的方法,找到原因了

配置多数据源required a single bean, but 2 were found:_第2张图片

加了一个@Primary注解,只要在其中的一个数据源配置类中加,这里提现到@Primary注解的作用
@Primary:自动装配时当出现多个Bean候选者时,被注解为@Primary的Bean将作为首选者,否则将抛出异常

你可能感兴趣的:(配置多数据源required a single bean, but 2 were found:)