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

  • 相关阅读:
    Ajax:创建提示工具
    Ajax:自动刷新
    Ajax:动态加载列表框
    The Elements of C# Style Packaging
    Ajax:读取响应首部
    Ajax:发送请求与处理响应
    XMLHttpRequest对象
    WPF学习:XAML概述
    Ajax:进度条
    Ajax:数据验证
  • 原文地址:https://www.cnblogs.com/javaWHL/p/12599840.html
Copyright © 2011-2022 走看看