MrWHL

博客园 首页 联系 订阅 管理

 

报错信息

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'preloantaskDataSource' defined in class path resource [org/yanmai/config/PreloantaskDataSourceConfig.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceInitializer': Invocation of init method failed; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected single matching bean but found 2: preloantaskDataSource,zwyDataSource

解释

没有类型为'javax.sql.DataSource'的合格bean:预期的单个匹配bean,但是找到了2:preloantaskDataSource,zwyDataSource

 

解决方案

1.如果使用的springboot版本是1.X 换成 2.X的

2.如果第一种方案不行的话 在其中一个数据源配置的config文件中加注解

@Primary


@Primary:在众多相同的Bean中,优先使用@Primary注解的Bean。

这个和@Qualifier有点区别,@Qualifier指的是使用哪个Bean进行注入。

 

posted on 2020-03-30 17:22  MrWHL  阅读(500)  评论(0编辑  收藏  举报