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

  • 相关阅读:
    Leetcode 109
    Leetcode 118
    js时间操作
    DWR搭建以及使用教程
    Ant 概念
    Eclipse 快捷键
    [eclipse] 三个操作技巧
    js call方法
    js验证密码强弱
    request getParameter getAttribute
  • 原文地址:https://www.cnblogs.com/javaWHL/p/12599840.html
Copyright © 2011-2022 走看看