zoukankan      html  css  js  c++  java
  • spingboot 配置多个数据源报错

    报错信息

    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进行注入。

  • 相关阅读:
    用iptables 实现本地端口转发
    hive查询
    IOS畅销榜
    java多线程系列7-停止线程
    java多线程系列6-阻塞队列
    java多线程系列5-死锁与线程间通信
    java多线程系列4-线程池
    java多线程系列3-线程同步
    java多线程系列2-线程控制
    java多线程系列1--线程实现与调度
  • 原文地址:https://www.cnblogs.com/javaWHL/p/12599840.html
Copyright © 2011-2022 走看看