spring boot mybatis 多数据源异常
来源:互联网 发布:w3cschool java教程 编辑:程序博客网 时间:2024/05/20 08:43
摘要:在做多数据源项目改造的时候,通过spring boot启动applicationContext.xml配置文件,老提示如下异常信息:
[2016-11-30 19:49:29 WARN o.s.c.a.AnnotationConfigApplicationContext ] Exception encountered during context initialization - cancelling refresh attemptorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$JdbcTemplateConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$JdbcTemplateConfiguration.dataSource; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [javax.sql.DataSource] is defined: expected single matching bean but found 2: dataSourceRead,dataSourceWriteat org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686) [spring-boot-1.2.5.RELEASE.jar:1.2.5.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) [spring-boot-1.2.5.RELEASE.jar:1.2.5.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:957) [spring-boot-1.2.5.RELEASE.jar:1.2.5.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:946) [spring-boot-1.2.5.RELEASE.jar:1.2.5.RELEASE]at com.sudaibear.cui.CuiApplication.main(CuiApplication.java:20) [classes/:na]Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$JdbcTemplateConfiguration.dataSource; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [javax.sql.DataSource] is defined: expected single matching bean but found 2: dataSourceRead,dataSourceWriteat org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]... 15 common frames omittedCaused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [javax.sql.DataSource] is defined: expected single matching bean but found 2: dataSourceRead,dataSourceWriteat org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1054) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]... 17 common frames omitted2016-11-30 19:49:29.609 INFO net.spy.memcached.MemcachedConnection: Shut down memcached client
从异常信息看,是spring boot启动注入了多个bean,而spring默认启动是注入一个bean,所以这里就提示只能有一个bean,进过查询,发现是spring boot在注入bean的时候的一个bug,spring boot启动默认是注入多个bean的,要解决这个问题,需要禁止spring boot启动注入多个bean,解决方法如下:
/** * 项目启动的入口<br> */@SpringBootApplication@ComponentScan(basePackages = {"com.micai.cui","com.micai.dubbo","com.micai.bill.config","com.micai.mq"})@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class,DataSourceTransactionManagerAutoConfiguration.class,}) @ImportResource({"classpath:applicationContext.xml"})public class CuiApplication { public static void main(String args[]) { SpringApplication.run(CuiApplication.class, args); System.out.println("启动成功"); }}
,这里主要是禁止spring boot启动注入多个bean
参考资料:http://blog.csdn.net/terry7/article/details/51996739
0 0
- spring boot mybatis 多数据源异常
- spring(spring-boot) + mybatis多数据源
- spring boot Mybatis多数据源配置
- spring boot+mybatis 多数据源切换
- spring boot+mybatis 多数据源切换
- spring boot + mybatis 多数据源配置
- 《spring-boot学习》-09-spring boot+mybatis多数据源
- Spring Boot下配置MyBatis多数据源
- Spring Boot下配置MyBatis多数据源
- Spring Boot下配置MyBatis多数据源
- Spring Boot + Mybatis多数据源和动态数据源配置
- spring boot中使用druid多数据源配置Mybatis
- Spring Boot 整合 Mybatis 实现 Druid 多数据源详解
- Spring Boot 整合 Mybatis 实现 Druid 多数据源详解
- Spring-boot下的mybatis多数据源JTA配置
- Spring Boot 整合 Mybatis 实现 Druid 多数据源详解
- Spring Boot 集成Mybatis实现多数据源
- spring boot下mybatis多数据源配置
- C语言以邻接表为存储结构的图的构造以及广度优先,深度优先遍历
- SRAM
- C语言 求一个数二进制码中1的个数 最短代码
- MySQL索引
- Elasticsearch配置文件详解
- spring boot mybatis 多数据源异常
- 51Nod 1085 背包问题
- 润乾填报表中如何上传图片到数据库
- [51nod1192]gcd表中的质数
- 到底什么是MFC?
- lintcode,搜索旋转排序数组
- 经典SQL查询语句大全
- CCS6.2超详细使用方法
- java编程题