标签:springboot found 数据源 Primary bean beans mysql org than
1.org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: more than one 'primary' bean found among candidates: [clusterDataSource, masterDataSource]
解决方案:spring boot 启动类加上 exclude = DataSourceAutoConfiguration.class 代表启动项目的时候 不加载这个类
2.Unsatisfied dependency expressed through method 'sqlSessionTemplate' parameter 0
解决方案:Pom中的<relativePath />
这一行需要被删掉
3.org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionTemplate' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionTemplate' parameter 0; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.apache.ibatis.session.SqlSessionFactory' available: more than one 'primary' bean found among candidates: [clusterSqlSessionFactory, masterSqlSessionFactory]
Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.apache.ibatis.session.SqlSessionFactory' available: more than one 'primary' bean found among candidates: [clusterSqlSessionFactory, masterSqlSessionFactory]
报错原因,两个config文件中的方法上都加了@Primary
解决方案:将其中一个配置文件中的@Primary注掉就好了
4.more than one 'primary' bean found among candidates: [clusterSqlSessionFactory, masterSqlSessionFactory]
解决方案:因为项目中引用到第三方jar,第三方jar 里可以也有对ObjectMapper使用@Primary,造成冲突,去掉代码中的@Primary解决异常
5.Parameter 0 of method sqlSessionTemplate in org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration required a single bean, but 2 were found
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
出现原因:两个配置文件中的方法上都没有(或者都有)@Primary注解
解决方案:
在springboot1.x时 datasource上要在一个写数据源上标记@Primary为主数据源
而在springboot2.X时则不需要
在其中一个配置文件中的方法上加上@Primary注解就好了
成功的方法:是在主masterConfig中的方法上加上@Primary
标签:springboot,found,数据源,Primary,bean,beans,mysql,org,than 来源: https://www.cnblogs.com/taosheng-yijiu/p/15096645.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。